View Full Version : How to load a Qwidget in groupBox at run time?
AviMittal
22nd June 2009, 15:07
How to load a Qwidget in groupBox at run time?
Thanks
Lykurg
22nd June 2009, 16:10
How to load a Qwidget in groupBox at run time?
Thanks
Well, your group box has a layout. Take that and use QLayout::addWidget()...
AviMittal
23rd June 2009, 07:24
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.
nish
23rd June 2009, 07:34
usrCtrl *ptr = new usrCtrl(ui.groupBox);
QVBoxLayout* layout=new QVBoxLayout;//create this only one time
layout->addWidget(ptr);
ui.groupBox->setLayout(layout);
//after this if u need the layout just call
//ui.groupBox->layout()->addSomething
edit: correction : layout->addWidget(ptr); instead of layout->addWidget(layout);
Lykurg
23rd June 2009, 08:06
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?
nish
23rd June 2009, 08:19
just guessing....
a) have you set already a layout to your group widget? Which type of layout do you use.
Ans. See next Question
b) what is ui.groupBox->layout() returning?
Ans. 0
AviMittal
25th June 2009, 08:17
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.
Lykurg
25th June 2009, 11:31
What's the output of
if (ui.groupBox->layout())
qWarning() << "valid pointer";
else
qWarning() << "invalid pointer";
And can we see the relevant part of the ui file
AviMittal
25th June 2009, 12:35
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.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.