PDA

View Full Version : Hiding a tab in QTabBar widget



erik
14th October 2008, 14:57
Hello, all!

Is it possible to hide particular tab in QTabBar widget instead of removing it from there? Or in order to accomplish such behavior I have to reimplement QTabBar in my own way?

elcuco
14th October 2008, 16:38
tabBar()->hide();


it's a widget, you can hide it without any problems. Note this is a protceted method, so you will need to derive QTabWidget to do this.

erik
14th October 2008, 16:43
elcuco,

My goal is to hide particular tab in QTabBar but not QTabBar widget in whole.

elcuco
14th October 2008, 16:51
then removeTab() is your friend. IMHO you will need to keep a reference to the contained widget, otherwise you will lose it.

erik
14th October 2008, 17:00
elcuco,

In other words, I don`t have any mean to hide tab except to remove it? This produces many inconveniences: for example if I want to show my tab later at the same place - I have to remember its index and properly update it in order to insert it in the same place.

lyuts
22nd October 2008, 15:22
I guess you have to write your own class (a subclass of QTabBar) and impelement your hideTab method. Looks like this is the only way.

erik
22nd October 2008, 15:40
lyuts,

Thank you, I have came to the same conclusion.

The only thing that afraid me a little - is need to reimplement Qt standard classes in order to achieve quite minor changes in a behaviour.

lyuts
22nd October 2008, 15:50
Well, if it is needed for your project then it is really worth of doing that. Who know, may be in future you'll need it again. Good luck.

Noremac
12th August 2011, 23:42
I came across this thread looking for how to hide a tab and came to the same conclusion as Erik, but then after looking at more documentation realized that, as Lyuts hinted very subtly earlier that it is through the removeTab() that you "hide" the tab. You can then addTab() later. If it was already included in the ui object, then you can always reference it from there and you don't need to store another reference.

Just thought I'd thrown in my comment to help any future seekers of the same answer as the removeTab seems to imply that it will be forever removed (despite the thread being 3 years old :p).

daniel347x
12th February 2017, 13:29
Noremac's simple answer works for me, 6 years later.