PDA

View Full Version : How to add Buttons in QDialog ?



npc
25th April 2007, 16:38
Hi,

I created a Dialog using Qt 3.3.7, now I want to add buttons and labels.

When I tried to add like this..


QDialog *dlg = new QDialog(0,"title");
dlg->setCaption( QDialog::tr( "Caption" ) );
QLabel* lbl = new QLabel("Test Label",dlg);
QPushButton* btn = new QPushButton("&press",dlg);
QPushButton* btn1 = new QPushButton("e&xit",dlg);


It overwrites the properties.

What is the correct way to do this?

Thanks,
*npc*

marcel
25th April 2007, 17:21
Why don't you use Designer to create your dialog? Especially if you have a lot of widgets to add. Also, by using Designer it is easier to design your layouts.

If you don't want/know to use Designer, you must subclass QDialog and add your widgets in the implementation of this subclass. You can find many examples on how to do this in the Qt examples.

Regards

wysota
25th April 2007, 17:35
You should use a layout if you want to add widgets to a dialog. Otherwise all widgets will be positions in the top left corner of the parent widget with an arbitrary size.