Results 1 to 9 of 9

Thread: How to load a Qwidget in groupBox at run time?

  1. #1
    Join Date
    May 2009
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to load a Qwidget in groupBox at run time?

    How to load a Qwidget in groupBox at run time?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to load a Qwidget in groupBox at run time?

    Quote Originally Posted by AviMittal View Post
    How to load a Qwidget in groupBox at run time?

    Thanks
    Well, your group box has a layout. Take that and use QLayout::addWidget()...

  3. #3
    Join Date
    May 2009
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11

    Post Re: How to load a Qwidget in groupBox at run time?

    Quote Originally Posted by Lykurg View Post
    Well, your group box has a layout. Take that and use QLayout::addWidget()...
    thanks for rplying. Hey but i tried following......and my program is crashing saying "segmentation fault".

    usrCtrl *ptr = new usrCtrl(ui.groupBox);
    ui.groupBox->layout()->addWidget(ptr);


    Explanation: I created a QWidget class "Tool" where i took a groupBox. i created another Qwidegt named
    "usrCtrl". Now what i want to do is to load this usrctrl in the Tool's groupBox at run time.

    Please suggest.

  4. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to load a Qwidget in groupBox at run time?

    Qt Code:
    1. usrCtrl *ptr = new usrCtrl(ui.groupBox);
    2. QVBoxLayout* layout=new QVBoxLayout;//create this only one time
    3. layout->addWidget(ptr);
    4. ui.groupBox->setLayout(layout);
    5. //after this if u need the layout just call
    6. //ui.groupBox->layout()->addSomething
    To copy to clipboard, switch view to plain text mode 

    edit: correction : layout->addWidget(ptr); instead of layout->addWidget(layout);

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to load a Qwidget in groupBox at run time?

    a) have you set already a layout to your group widget? Which type of layout do you use.
    b) what is ui.groupBox->layout() returning?

  6. #6
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to load a Qwidget in groupBox at run time?

    just guessing....

    Quote Originally Posted by Lykurg View Post
    a) have you set already a layout to your group widget? Which type of layout do you use.
    Ans. See next Question

    Quote Originally Posted by Lykurg View Post
    b) what is ui.groupBox->layout() returning?
    Ans. 0

  7. #7
    Join Date
    May 2009
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to load a Qwidget in groupBox at run time?

    thanks. Actually i am designing the screens by using qt designer. so layout is already applied during screen design. I applied grid layout.
    But now i want to load the Qwidget control in a groupbox ( on which layout is already applied at design time) at run time.

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to load a Qwidget in groupBox at run time?

    What's the output of
    Qt Code:
    1. if (ui.groupBox->layout())
    2. qWarning() << "valid pointer";
    3. else
    4. qWarning() << "invalid pointer";
    To copy to clipboard, switch view to plain text mode 
    And can we see the relevant part of the ui file

  9. #9
    Join Date
    May 2009
    Posts
    31
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to load a Qwidget in groupBox at run time?

    hey output is "Invalid ptr".
    I checked the code..and layout is applied on complete form
    So if u do

    ui.gridLayout->addWidget(usrctrl*, row,col)
    then it works.
    but for that i need to explicitly find out the layout name applied on form. that we can do using layout() funcion call. But i can also add Qwidget to the form.

    but the layout option has only following function call
    layout()->addWidget(QWidget).
    where as i need addWidget(QWidget, row, col)

    i need row/col position as well to add the QWidget at the appropriate place on the form.

Similar Threads

  1. Load WebKit dll at run time
    By Lele in forum Qt Programming
    Replies: 2
    Last Post: 10th September 2008, 09:11
  2. Display a QWidget on two X-Server at the same time
    By tarod in forum Qt Programming
    Replies: 0
    Last Post: 1st July 2008, 12:55
  3. QDateTime GMT add sec. or - sec. from locale time....
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 20th February 2007, 16:39

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.