0

I would like to change the default background colour of my QT-application (QT 4.8.6 based) to a different (darker) grey. I did this by adding

background-color: #A3A3A3;

to the QWidget-section in my QSS file. This works well, with the exception of the tabs. When I don't have this line the tabs in my application look OK, so the selected tab does not have a line between the tab and the tab-widget, all the others have a border (works for both top and bottom tabs).

When I add the background-color the line between the (unselected) tabs and the tab-widget disappears, both for top and bottom tabs. I tried adding a border to the tab-widget-pane, but this also adds a border between the selected tab and the tab-widget.

How can I change the background colour of my application and still have the tabs look as they should?

Update:

As requested the QSS file. I removed everything not related to this issue:

QWidget
{
   font-weight: bold;
   background-color: #A3A3A3;
}

QTabBar::tab:!selected
{
   font-weight: normal;
}

With this QSS file the background is darker, but there are no lines between the tabs and the pane. When I disable the background-color line the tabs are shown OK (but the window becomes light-gray of course).

Also an image indicating the problem:

Problem with tabs

Borkhuis
  • 141
  • 3
  • 11
  • 1
    When you add a style-sheet item for any `QWidget`, beware that it usually blows away any preexisting default styling. The best thing to do is *fully* style the control, its sub-controls, and pseudo-states from the beginning. You can also change the background color through the palette, but I wouldn't recommend it as style-sheets are more powerful, and palettes and style sheets don't play very nicely together. – Nicolas Holthaus Nov 16 '15 at 13:27
  • Thanks for your answer. I was afraid of this, and it looks like the separation between the the tabs and pane is also widget-based, and thus gets the same colour. Is there any way to extract the complete stylesheet from a window, so that I can reuse this to get a different background? – Borkhuis Nov 17 '15 at 06:58
  • No, you can't get the stylesheet unless you read it as a text file from disk or your qrc or something. Bad approach. You're better off figuring out which widget/subcontrol needs to have it's border color adjusted and just *also* do that in the style sheet. If I read the problem right, I think it's one of the QTabBar or QTabWidget controls. Check out the reference: http://doc.qt.io/qt-4.8/stylesheet-reference.html – Nicolas Holthaus Nov 17 '15 at 13:15
  • also, posting your stylesheet where you attempted to fix the tab border may help in figuring out what you need to do. I'm pretty sure this can/should all be fixed from within the stylesheet. – Nicolas Holthaus Nov 17 '15 at 13:17
  • Nicolas, I updated the question with the reduced QSS file. I only left the parts that are related to this, and the problem is still there. – Borkhuis Nov 18 '15 at 09:55

0 Answers0