Reputation: 1
I have Tabbar in my form, What I want is to differentiate Active and Inactive Tab with different color text in it. My code is as below. I don't understand what is missing in it, It always show QPalette::Active text color in all the tab
QPalette Palette;
QTabBar* pTabBar = tabBar();
pTabBar->setAutoFillBackground(false);
pTabBar->setDrawBase(true);
Palette.setColor(QPalette::Active, QPalette::Window, QColor(255, 255, 255));
Palette.setColor(QPalette::Active, QPalette::WindowText, QColor(117, 121, 124));
pTabBar->setPalette(Palette);
Palette.setColor(QPalette::Inactive, QPalette::Window, QColor(171, 175, 178));
Palette.setColor(QPalette::Inactive, QPalette::WindowText, QColor(64, 68, 71));
pTabBar->setPalette(Palette);
Upvotes: 0
Views: 454
Reputation: 1
I fix this by using QPalette
QTabBar* pTabBar = new QTabBar();
QPalette p = pTabBar->palette();
p.setColor(QPalette::Window, QColor(255,255,255));
p.setColor(QPalette::Button, QColor(255,255,255));
pTabBar->setPalette(p);
Upvotes: -1
Reputation: 8321
QPalette
is used as an input for the current style (QStyle
). The exact usage of the palette is left to the style. Some styles may use the set palette, but some others may choose to completely ignore the palette. For instance the GTK style completely ignores it.
Maybe you can try changing the style to see if it changes something. You can either set the style on a particular widget or application wide with QApplication::setStyle()
.
As suggested by @saeed, using style sheet can be an option. But I personnally never use it as it can break the style.
Upvotes: 1