Results 1 to 3 of 3

Thread: How to add Buttons in QDialog ?

  1. #1
    Join Date
    Mar 2006
    Posts
    53
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default How to add Buttons in QDialog ?

    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..
    Qt Code:
    1. QDialog *dlg = new QDialog(0,"title");
    2. dlg->setCaption( QDialog::tr( "Caption" ) );
    3. QLabel* lbl = new QLabel("Test Label",dlg);
    4. QPushButton* btn = new QPushButton("&press",dlg);
    5. QPushButton* btn1 = new QPushButton("e&xit",dlg);
    To copy to clipboard, switch view to plain text mode 

    It overwrites the properties.

    What is the correct way to do this?

    Thanks,
    *npc*

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to add Buttons in QDialog ?

    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

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to add Buttons in QDialog ?

    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.

  4. The following user says thank you to wysota for this useful post:

    selmi.asma (19th July 2013)

Similar Threads

  1. QDialog resize ?
    By allensr in forum Qt Programming
    Replies: 6
    Last Post: 28th October 2007, 22:41
  2. Resizing a QDialog to the content size
    By Nyphel in forum Qt Programming
    Replies: 8
    Last Post: 15th March 2007, 08:16
  3. Qdialog as a child widget
    By dave in forum Newbie
    Replies: 12
    Last Post: 14th November 2006, 09:43
  4. array of radio buttons
    By amulya in forum Qt Programming
    Replies: 4
    Last Post: 5th October 2006, 12:59
  5. How to get larger radio buttons on XP?
    By Ben.Hines in forum Qt Programming
    Replies: 9
    Last Post: 24th April 2006, 19:00

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.