Reputation: 1974
I have 2 QTabWidgets in a window that contain QWidgets and a additional button intended to collapse the tab content which controls visibility. Either both are visible or one is hidden.
When I set the widget visibility using the code below, the widgets disappear, but the tab widget doesn't resize.
for(int i = 0; i < tabWidget->count(); i++) {
tabWidget->widget(i)->setVisible(!hide);
}
I am left with a blank box and a frame around the edge, but nothing in the window resizes
What I would like to happen is for the tab widget that is still visible to expand to take up the whole window, but for the other tab widget's bar to still be visible.
It is possible to hide just the tab bar. Is there any way to hide the tab content and leave the bar visible?
Upvotes: 0
Views: 494
Reputation: 61
Here are a couple of options, one of which is similar to hiding tabs in a QTabWidget.
1. Replace the tabs with dummy widgets.
You still want the tabs to show, so swap them out with an empty widget so the calculated height of the contents of the QTabWidget is 0.
2. Hide the contents of the tab's widget rather than the widget itself.
You most likely have a layout within these widgets, the layout spacing and margins will show as empty space. You would need to work out the details of hiding the contents easily.
3. Set the maximum height of the QTabWidget
Set the maximum height of the QTabWidget to the height of the QTabWidget's QTabBar.
if (hide) {
tabWidget->setMaximumHeight(tabWidget->tabBar()->height());
} else {
tabWidget->setMaximumHeight(QWIDGETSIZE_MAX); // Default maximum size for qWidgets
}
I did not see that setting QSizePolicy on either of the tab widgets had an effect. Tested on Qt 5.13.1.
Upvotes: 2