Hide tab previously added to Qt TabWidget

I have a dialog containing Qt TabWidget with the addition of several tabs.

I would like to hide one of the tabs.

_mytab->hide() 

does not work. I don’t want to just delete the tab and all its widgets from the .ui file, because the other code depends on the widgets in the tab. However, it would be nice to create a tab code, but somehow not :: insertTab in the generated uic_mydialog.cpp file. Setting a hidden property in the ui file also does not work.

I am using Qt 3.3

+6
c ++ qt
source share
2 answers

I would use QTabDialog :: removePage (QWidget * pTabPage), which does not remove pTabPage, what you need.

 _myTabDlg->removePage(_mytab); 

I use it and it works great!

+6
source share

I ran into the same problem. I use the following approach.

Now here is the data.

genTab is the name of my QTabWidget

tabX is the name of the tab that I want to delete.

(Note that this is the second tab in the widgets of the tab. Therefore, I will use "1" as an index to link to this tab)

The code to remove and add is below.

 ui.genTab->removeTab(1); // removes the tab at the index 1 which is the second tab from left ui.genTab->insertTab(1, ui.tabX, "<Name of TabX>"); // The tab is added back. 

Note here that this is easy to do if you have a tab added statically during development. Since we will have the name of the object associated with the tab, and therefore we can refer to it using ui.tabX. From what you say, in your case the tab is really added statically at design time.

However, if you add tabs dynamically, then you probably have to keep tabs in the list, and then have another list for the deleted tables.

But the first solution is likely to work for you. Hope this helps.

-Arjun

+10
source share

All Articles