tags:

views:

59

answers:

3

I would like to style individual tabs of the tab bar of a QTabWidget (not hover or current but an individual one) WHY? because I need to get the user's attention so that he knows urgent information appeared in that tab. There can be multiple tabs that need attention.

+1  A: 

This seems a little strange. Why don't you start with that tab selected?

I don't think you can do that with stylesheets. You can easily customize first and last but not any tab (AFAIK)

http://doc.trolltech.com/4.6/stylesheet-reference.html

On the other hand you can set custom icon to draw attention or use void QTabBar::setTabTextColor ( int index, const QColor & color )

Anton
the reason I am doing this is because each tab displays data for a piece of Hardware equipment. if a fault occurs then its an emergency and they need to know where the fault is coming from and get to the corresponding tab. That is why a selected tab is not sufficient.
yan bellavance
As pointed out by Anton, you could color the tab. If it's an emergency than switching tabs may be warranted. Other options include using a popup or having an alert widget that becomes visible when a fault occurs.
Kaleb Pederson
How about adding QLabel above tabs with message that something bad happen and link/button which navigates to the tab in question. When there is no error the message will be hidden.
Anton
that is one of my options but I dint want to go there.
yan bellavance
@Kaleb: only the text color can be changed. That might not grab enough attention to it but it could do for now.
yan bellavance
+1  A: 

You would have to assemble your own tab widget but i think if you subclass QTabBar and use setTabButton(int index, ...) you can set a custom widget for the item in the tab, this would let you control the behaviour and you could change it through code or style it via the property selector e.g.

QTabBar MyButtonWidget[showalert=true] 
{
   background-color: red;
}
Harald Scheirich
A: 

You might want to try simply using stylesheets to directly style a tab instead of subclassing just for that purpose. In the stylesheet, you can use the :tab subcontrol to access a single tab, and you can then modify a dynamic propoerty to set its state as either needing attention or not, and applying the style based on the dynamic property.

See : :tab sub control , Customizing using dynamic properties

Fred
no that would not work, i cannot select exactly which tab to style. For example if I have 15 tabs i cant say :tab:3 only tab:left tab:right, tab:middle etc..
yan bellavance
@yan: you could, however, use QTabBar::tab[urgent="true"], then in your code, set a dynamic property on the tab that needs attention with aTab->setProperty("urgent", true); when appropriate
Fred
would like to beleive you but I just tried it and it doesn't seem to work. Probably I am not doing right but I don't see a way of adding a dynamic property to an individual tab, only to the whole QTabWidget or QTabBar. If you could add more detail I will try it.
yan bellavance