How to load a Qwidget in groupBox at run time?
Thanks
How to load a Qwidget in groupBox at run time?
Thanks
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.
Qt Code:
usrCtrl *ptr = new usrCtrl(ui.groupBox); layout->addWidget(ptr); ui.groupBox->setLayout(layout); //after this if u need the layout just call //ui.groupBox->layout()->addSomethingTo copy to clipboard, switch view to plain text mode
edit: correction : layout->addWidget(ptr); instead of layout->addWidget(layout);
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?
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.
What's the output ofAnd can we see the relevant part of the ui fileQt Code:
if (ui.groupBox->layout()) qWarning() << "valid pointer"; else qWarning() << "invalid pointer";To copy to clipboard, switch view to plain text mode
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.
Bookmarks