QTabWidget, setting colour of tab itself ?
-
You can not change it with style sheet? My suggestion for you was to flash the icons on the tabs.
-
@JoeCFD , unfortunately not....I've been through this loop, the class I found and have linked to is supposed to work, but I can't get it to work...could it be due to Qt 4.8 ?
@SPlatten Probably. 4.8 is ancient code. Nobody here will try 4.8 for you. It is amazing that the people still have patience to use it. Poor you.
Let me check my code to see if you can use tabbar to change the color. But my code is much more customized.
-
@SPlatten Probably. 4.8 is ancient code. Nobody here will try 4.8 for you. It is amazing that the people still have patience to use it. Poor you.
Let me check my code to see if you can use tabbar to change the color. But my code is much more customized.
-
@JoeCFD , unfortunately its completely out of my control and the company using it won't be updating it anytime soon as there are other dependencies / reasons why they can't.
-
- 4.8 qtabbar_cpp source code is here. copy line 1569 to 1648 to your paint event. Not sure if this will work.
https://dreamswork.github.io/qt4/qtabbar_8cpp_source.html
painting of tabs is done at line 1622. - Look at lines 1594 and 1595. These lines call initStyleOption() to create QStyleOptionTabV3 tab for each tab which is a subclass of QStyleOption
https://dreamswork.github.io/qt4/classQTabBar.html#a41b394d892263b6b5a0705fb979f3c8e
and each QStyleOption has a public palette with background color. You can change it. Try to print out the background color to see what it is. - you can find QStyleOptionTabV3 and QStyleOptionTab here
https://dreamswork.github.io/qt4/qstyleoption_8h_source.html
This way may be simpler. Good luck.
- 4.8 qtabbar_cpp source code is here. copy line 1569 to 1648 to your paint event. Not sure if this will work.
-
@JoeCFD , the company is a world wide provider of defence and weapon tech....they're clients are governments and the equipment is years out of date, again, I have requested an updated, but I can't do anything about it.
-
- 4.8 qtabbar_cpp source code is here. copy line 1569 to 1648 to your paint event. Not sure if this will work.
https://dreamswork.github.io/qt4/qtabbar_8cpp_source.html
painting of tabs is done at line 1622. - Look at lines 1594 and 1595. These lines call initStyleOption() to create QStyleOptionTabV3 tab for each tab which is a subclass of QStyleOption
https://dreamswork.github.io/qt4/classQTabBar.html#a41b394d892263b6b5a0705fb979f3c8e
and each QStyleOption has a public palette with background color. You can change it. Try to print out the background color to see what it is. - you can find QStyleOptionTabV3 and QStyleOptionTab here
https://dreamswork.github.io/qt4/qstyleoption_8h_source.html
This way may be simpler. Good luck.
- 4.8 qtabbar_cpp source code is here. copy line 1569 to 1648 to your paint event. Not sure if this will work.
-
@SPlatten
Without wanting to digress this thread. I am surprised given the age of an old 4.8 implementation they now insist they want a change in a tab colour! Can't you say "Sorry, I have looked into it, this old version won't let me do that" ? -
@J.Hilk, @JonB , @JoeCFD, I tried another tack...that is calling tabButton of QTabBar to get the tab widget, I was then going to try setting the widget style sheet, however failed at the first hurdle:
int intTabs(count()); //This returns 10, which is the number of tabs for( int intTab=0; intTab<intTabs; intTab++ ) { QString strText(tabText(intTab)); //This works and gets the tab text, e.g. &Overall QWidget* pobjTab(tabButton(intTab, QTabBar::LeftSide)); if ( !pobjTab ) { pobjTab = tabButton(intTab, QTabBar::RightSide); } }
Calling tabButton with QTabBar::LeftSide or QTabBar::RightSide returns NULL. Have I done something wrong or is this something else that doesn't work in 4.8 ?
-
- 4.8 qtabbar_cpp source code is here. copy line 1569 to 1648 to your paint event. Not sure if this will work.
https://dreamswork.github.io/qt4/qtabbar_8cpp_source.html
painting of tabs is done at line 1622. - Look at lines 1594 and 1595. These lines call initStyleOption() to create QStyleOptionTabV3 tab for each tab which is a subclass of QStyleOption
https://dreamswork.github.io/qt4/classQTabBar.html#a41b394d892263b6b5a0705fb979f3c8e
and each QStyleOption has a public palette with background color. You can change it. Try to print out the background color to see what it is. - you can find QStyleOptionTabV3 and QStyleOptionTab here
https://dreamswork.github.io/qt4/qstyleoption_8h_source.html
This way may be simpler. Good luck.
- 4.8 qtabbar_cpp source code is here. copy line 1569 to 1648 to your paint event. Not sure if this will work.
-
@J.Hilk, @JonB , @JoeCFD, I tried another tack...that is calling tabButton of QTabBar to get the tab widget, I was then going to try setting the widget style sheet, however failed at the first hurdle:
int intTabs(count()); //This returns 10, which is the number of tabs for( int intTab=0; intTab<intTabs; intTab++ ) { QString strText(tabText(intTab)); //This works and gets the tab text, e.g. &Overall QWidget* pobjTab(tabButton(intTab, QTabBar::LeftSide)); if ( !pobjTab ) { pobjTab = tabButton(intTab, QTabBar::RightSide); } }
Calling tabButton with QTabBar::LeftSide or QTabBar::RightSide returns NULL. Have I done something wrong or is this something else that doesn't work in 4.8 ?
@SPlatten said in QTabWidget, setting colour of tab itself ?:
Calling tabButton with QTabBar::LeftSide or QTabBar::RightSide returns NULL. Have I done something wrong or is this something else that doesn't work in 4.8 ?
I believe either (a) the
QTabBar
does not have anyQWidget
s on/for its tabs at the time you call this or (b) it never has anyQWidget
on/for its tabs unless you callQTabBar::setTabButton(int index, QTabBar::ButtonPosition position, QWidget *widget)
. -
- 4.8 qtabbar_cpp source code is here. copy line 1569 to 1648 to your paint event. Not sure if this will work.
https://dreamswork.github.io/qt4/qtabbar_8cpp_source.html
painting of tabs is done at line 1622. - Look at lines 1594 and 1595. These lines call initStyleOption() to create QStyleOptionTabV3 tab for each tab which is a subclass of QStyleOption
https://dreamswork.github.io/qt4/classQTabBar.html#a41b394d892263b6b5a0705fb979f3c8e
and each QStyleOption has a public palette with background color. You can change it. Try to print out the background color to see what it is. - you can find QStyleOptionTabV3 and QStyleOptionTab here
https://dreamswork.github.io/qt4/qstyleoption_8h_source.html
This way may be simpler. Good luck.
- 4.8 qtabbar_cpp source code is here. copy line 1569 to 1648 to your paint event. Not sure if this will work.
-
@SPlatten said in QTabWidget, setting colour of tab itself ?:
Calling tabButton with QTabBar::LeftSide or QTabBar::RightSide returns NULL. Have I done something wrong or is this something else that doesn't work in 4.8 ?
I believe either (a) the
QTabBar
does not have anyQWidget
s on/for its tabs at the time you call this or (b) it never has anyQWidget
on/for its tabs unless you callQTabBar::setTabButton(int index, QTabBar::ButtonPosition position, QWidget *widget)
. -
@JonB , (b) is the case, I was hoping that each button on the tab bar was a widget available via this call.
@SPlatten
I think/suspect not. By default it does not use/place anyQWidget
on/for the tabs, rather something internal (just the text on the tab, no special widget).Mind you, if it helps your case (I don't know if it does) you could explicitly use
QTabBar::setTabButton()
to put your own widget there, then you can access that widget. I don't know whether that would aid you in your issue.You were referred to https://stackoverflow.com/questions/46137500/qt-tabwidget-each-tab-title-background-color. There in answer https://stackoverflow.com/a/46139321/489865 you are shown a picture with the tabs having their own (different) colors. Could you state clearly and unequivocally whether (a) this is what you want and (b) (if so) why you can't use that solution?
-
@SPlatten
I think/suspect not. By default it does not use/place anyQWidget
on/for the tabs, rather something internal (just the text on the tab, no special widget).Mind you, if it helps your case (I don't know if it does) you could explicitly use
QTabBar::setTabButton()
to put your own widget there, then you can access that widget. I don't know whether that would aid you in your issue.You were referred to https://stackoverflow.com/questions/46137500/qt-tabwidget-each-tab-title-background-color. There in answer https://stackoverflow.com/a/46139321/489865 you are shown a picture with the tabs having their own (different) colors. Could you state clearly and unequivocally whether (a) this is what you want and (b) (if so) why you can't use that solution?
@JonB , in my code I am now writing the geometry of each tab when each is selected to the log file and I can see the geometry is correct , I can also see that the selection of the correct colour is chosen, but is this code correct:
opt.palette.setColor(QPalette::Button, QColor(kErrorColour));
opt is obtained from a call to:
initStyleOption(&opt, intTab);
Where intTab is 0 to N and opt is defined as QStyleOptionTab.
-
@JonB , in my code I am now writing the geometry of each tab when each is selected to the log file and I can see the geometry is correct , I can also see that the selection of the correct colour is chosen, but is this code correct:
opt.palette.setColor(QPalette::Button, QColor(kErrorColour));
opt is obtained from a call to:
initStyleOption(&opt, intTab);
Where intTab is 0 to N and opt is defined as QStyleOptionTab.
@SPlatten
Does not seem unreasonable. Would not work if (a)kErrorColour
's value is not acceptable toQColor
or (b) you are using a stylesheet on the element, as stylesheets override palette changes.Have you first tried the code shown in that SO solution? Does that work for you as they show? Then you can fiddle with changing that to whatever it is you want till it works or goes wrong.