How to stop child QTabWidget to inherit style sheet from parent QTabWidget

1.3k Views Asked by At

I have done below styling on QTabWidget (which has a QTabWidget inside one of it's tab):

QTabBar::tab {
    border: 2px solid grey;
}
QTabBar::tab:selected {
    border-color: red;
}

After this the tab widget looks like:

enter image description here

I do not want child QTabWidget to inherit style from parent. I know one way to achieve this is by using object name in style sheet but I don't have the object name of QTabBar associated with QTabWidget. Please let me know how I can achieve the desired behavior.

1

There are 1 best solutions below

2
rocambille On BEST ANSWER

You can use object name on the QTabWidget:

parent_tab_widget->setObjectName("parent_tab_widget");

In style sheet:

#parent_tab_widget > QTabBar::tab {
    border: 2px solid grey;
}
#parent_tab_widget > QTabBar::tab:selected {
    border-color: red;
}

More info on style sheet selectors in Qt4 here. The answer is a combination of the ID selector with the child selector.