This is the original Tabwidget without setting title background color
My customer ask me to do something like this; Set different background colour for title
All - Yellow
purchase - light blue
POS Sales - light green
Cash Sales - Pink
invoice - light purple
I have try the SetStyleSheet like:
QTabBar {
background-color : Yellow;
}
But all tab Color changed Somebody know how to setting each QTabBar background color?
These properties can not be set through QSS. To change the style to each tab we must create a custom
QTabBar
and override itspaintEvent
method, to be able to change the style of each tab we use theQStyleOptionTab
class, but to change theQTabWidget
tabbar we need to use thesetTabBar
method but this is private so you need to create a customQTabWidget
as shown below:tabwidget.h
And to use it in our QTabWidget in Qt Designer should be promoted for this we right click on the tabwidget and select the menu Promoted Widgets, in my case the previous code is created in the file tabwidget.h so this will be the header file and in the case of Promoted Class Name we use TabWidget, after that we press the buttons Add and Promote obtaining what is shown in the following image:
The final result is shown in the following image:
The complete example can be found in the following link