Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide a tab previously added to Qt TabWidget

Tags:

c++

qt

I've a dialog which contains a Qt TabWidget with a number of tabs added.

I'd like to hide one of the tabs.

_mytab->hide() 

doesn't work. I don't want to just delete the tab and all its widgets from the .ui file because other code relies on the widgets within the tab. However, it would be fine to generate the tab code but somehow not ::insertTab in the generated uic_mydialog.cpp. Setting the hidden property in the ui file does not work either.

I'm using Qt 3.3

like image 724
user23434 Avatar asked Oct 16 '08 09:10

user23434


2 Answers

I had encountered the same problem. I am using 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 remove.

(Note that this is the second tab in the Tab Widget. Hence, i will be using "1" as the index to refer to this tab)

The code to remove and add is as 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.

Here, note that it is easy to do this if you have the tab added statically in the design time. Because we will have an object name associated with the tab and hence we can refer to it using, ui.tabX. From what you say, in your case the tab is indeed added statically in the design time.

However, if you are adding the tabs dynamically, then probably you will have to maintain the tabs in a list and then have another list for deletedTabs.

But the first solution will most likely work for you. Hope this helps.

-Arjun

like image 172
AMM Avatar answered Oct 31 '22 02:10

AMM


I would use QTabDialog::removePage(QWidget* pTabPage) which does not delete pTabPage, which is what you want.

_myTabDlg->removePage(_mytab);

I'm using it and it works fine !

like image 8
Jérôme Avatar answered Oct 31 '22 03:10

Jérôme