qtqwidgetqtguiqt3

Qt 3 - adding a widget to an already existing widget and its layout


I have a QDialog created in designer with a QFrame testFrame which I've added a QHBoxLayout to, and at some point after the whole thing has been created and shown I am trying to programatically create a new widget with the QFrame as a parent. Whatever I try the new widget won't display:

End of init() method:

QBoxLayout *testFrameLayout = new QHBoxLayout(this->testFrame); //QT3 docs use QBoxLayout pointer when creating QHBoxLayout

During an event (e.g. a separate button has been pressed)

testButton = new QPushButton(this->testFrame);
testButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed, false);
testButton->setMaximumWidth(50);
testButton->setMaximumHeight(50);
testButton->setMinimumWidth(50);
testButton->setMinimumHeight(50);

testFrameLayout->addWidget(testButton);

I get this behaviour with different widgets, container classes (e.g. QGrid where I don't have to manage any layout stuff), calling update()/repaint() (on testFrame, testButton, the dialog itself) e.t.c, whatever I try it works when done in init() but not if done after the dialog has been displayed. I must be missing something, so any help would be appreciated!

Note: I am working on a very large project that uses Qt 3, so solutions must be compatible with this version.


Solution

  • Calling

    testButton->show();
    

    at the end solved this problem. Since using adjustSize() on the frame without show() on the actual button made the frame disappear, I think that maybe widgets are hidden until explicitly shown when added in like this.