dolphin boy
dolphin boy

Reputation: 113

Qt How to set background color for QTabBar content?

I have found the common way to style a QTabBar content background with a stylesheet is like:

QTabWidget QWidget {
    background-color: green;
}

The result would be like the desired one:

enter image description here

But problem is that QWidget also applies the background color to all objects inside the QTabWidget, that is, QToolButtons, QPushButtons, QFrames, etc... It's a pain in the ass for me because I need to apply once again all the background to my elements that are placed inside the tabs like:

QTabWidget QPushButton,
QTabWidget QToolButton {
     background-color: red;
}
... (and so on)

I don't think it is a smart solution because I also have nested QTabWidgets so it turns crazy because I need to "reset" all backgrounds element each time I nest a new QTabWidget inside the previous one...

I would be perfect to have access to the direct element or subelement "background"... Any idea?

Thank you

Upvotes: 0

Views: 1726

Answers (2)

dolphin boy
dolphin boy

Reputation: 113

This is the better solution I found:

QTabWidget::pane {
    background-color: red;
}

Upvotes: 0

ThorngardSO
ThorngardSO

Reputation: 1211

Try this:

QTabWidget QStackedWidget > QWidget  
{
    background-color: green;
}

Upvotes: 2

Related Questions