View Full Version : QTabWidget tab visibility

30th January 2007, 01:33
Hello all,

I have an application where the user edits various objects onscreen by right clicking on them. The dialog box that opens when the user does this has a QTabWidget in it. The first tab is standard across all of the elements, but the other tabs are not.

What I want to do, is use Designer to create the tabs for each of the different specialized setup features of the elements and then only display the tabs that are relevent to the particular element being edited. It is also possible that the user might change the type of element they are editing which requires an immediate change to the list of tabs displayed.

The problem I have run into, which I hadn't expected to, was the ability to hide tabs. I have created the tabs, can set them enabled or not, but disabling them only grays them out, I need them out of sight, but still available for display should the user change to an element that needs them.

I tried grabbing the pointer to the widget for each tab and using show() and hide() but this didn't have the desired effect, unless I goofed it.

Anybody got any ideas on how to do this? Otherwise, I'll have to do each of the forms in code and just add and delete pages manually. If I didn't need to be able to dynamically replace the pages, I could have just deleted the ones I didn't need. Oh well.

Thanks for any thoughts anybody has.


30th January 2007, 15:35
You can use QTabWidget::removeTab() to remove tabs, but make sure you store a pointer to the removed page somewhere, so that you can add it later. You can also design all pages as separate .ui files and fill your tab widget in the code.

31st January 2007, 00:24
Thanks - I'll give it a try!