PDA

View Full Version : QTabBar and different background color



smrtak
15th November 2009, 15:36
I want change color all tab different color, but i dont find the solution.
I try overload the class QTabBar and QTabWidget, but its not possible? paintEvent have some private class and variables...

I have idea overload the QTabBar::initStyleOption, add here only one line to change background color for tab index, but this function its not VIRTUAL :mad:

qt 4.5.1

Any idea?

Sorry for english

high_flyer
16th November 2009, 10:29
No need to subclass anything.
Just use QPalette.

smrtak
17th November 2009, 15:39
No need to subclass anything.
Just use QPalette.

Can you give me little example how to set background color only for second tab?

high_flyer
18th November 2009, 16:02
I didn't understand that you wanted each tab to have a different color, that is a different matter.

Hmm... maybe you can work around it by setting an icon, and setting its size to the tab size...

The other way (that I see) is to override the QTabBar::paintEvent() but you should know if you are up to it.

smrtak
18th November 2009, 19:10
my bad english.. :)



The other way (that I see) is to override the QTabBar::paintEvent() but you should know if you are up to it.
tihs function use some a private member of private class... looks very hard... i think QTabBar not have good support for override :(



Hmm... maybe you can work around it by setting an icon, and setting its size to the tab size....
this is good idea, but here can be problem with translation support ( tr() ), i must use icon + text, .. i try this way, thx for help :)

tferreira
15th May 2012, 16:49
I've tried to override paintEvent(), but without success so far.
Was anyone able to do this?