Reputation: 111
I am trying to build a GUI which will:
QTabwidget
(of many predefined in Qt Designer .ui
)I plan to make a QTabwidget
with, say 10 tabs, but only one should be visible based on the parameters loaded. Enabling certain tab is not an option since it takes to many space and the disabled tabs are grey. I do not want to see disabled tabs.
Removing tab could be an option but the index is not related to a specific tab so I have to take care of the shift in the indices. And furthermore if user loads another file with different parameters, a good tab should be added and the current one removed.
My questions are:
RemoveTab
, how to use pointers on tabs, rather than indices?I use PyQt4
Upvotes: 1
Views: 9084
Reputation: 73
I see that this thread is kinda old. But I hope this will still help. You can use the remove() method to "hide" the tab. There's no way to really hide them in pyqt4. when you remove it, it's gone from the ui. But in the back end, the tab object with all your settings still exist. I'm sure you can find a way to improvise it back. Give it a try!
Upvotes: 0
Reputation: 120578
Use a QStackedWidget
, which is exactly the same as a tab-widget, but without the tab-bar (which you don't need).
This widget is available in Qt Designer. The context menu has several commands for adding/removing pages and so forth. Note that the arrow buttons in the top-right corner are just there for convenience: they won't appear in your application.
Pages can be added/removed at runtime with addWidget/removeWidget
:
index = self.stack.addWidget(self.page1)
self.stack.removeWidget(self.page1)
You can access the pages using either indexes or widget references.
Upvotes: 5