Unsolved QTabWidget hides a child widget and cannot show it again (Qt 5.12.2, mingw64, Windows 7)
-
Qt 5.12.2, mingw64, Windows 7
I need to create a tab with two widgets: custom widget and a button. I did:auto vbox = new QVBoxLayout; vbox->addWidget(customWidget); auto pb = new QPushButton("my button"); vbox->addWidget(pb); vbox->addStretch(); auto w = new QWidget(); w->setLayout(vbox); tw_main = new QTabWidget; tw_main->addTab(w, "my tab");
And the first time there are no problems. And "w" widget is shown all. But when I close the tw_main widget and then open it again, there is only a button in "my tab".
When I debug this behavior, I find out that the customWidget is not shown again (file qwidget.cpp, in func showChildren(bool)) because it has the Qt::WA_WState_Hidden attribute.
If I insert the customWidget without the proxy widget w, I get normal behavior.Now I cope with this problem by next code:
void MyMainForm::showEvent(QShowEvent *ev) { if (customWidget) { customWidget->setVisible(true); } }
-
Hi,
What version of Qt ?
What OS ?
Can you provide a complete minimal example that shows that behavior ? -
w is not a child of tw_main or customWidget. Therefore it is not displayed when tw_main->setVisible( true ), right? make customWidget to be w's parent. Try it again.
-
@JoeCFD I read about addTab function: "Ownership of page is passed on to the QTabWidget." Why do you think that w is not a child of tw_main? And I read about w->setLayout(): "The QWidget will take ownership of layout." Then I read about vbox->addWidget: "When you use a layout, you do not need to pass a parent when constructing the child widgets. The layout will automatically reparent the widgets (using QWidget::setParent()) so that they are children of the widget on which the layout is installed." So tw_main owns w and w owns customWidget. (And I saw the customWidget in the child list of w in the debug mode)
-
Please check with a more recent Qt version (5.12.8 will be enought if you can't update to 5.15). I think there was a bug around not showing dialogs after the first show somewhere in 5.12.x but don't know if this also affected QTabWidgets. Maybe also search the bugtracker.