Sajal
Sajal

Reputation: 1853

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

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.

Upvotes: 1

Views: 1443

Answers (1)

rocambille
rocambille

Reputation: 15976

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.

Upvotes: 1

Related Questions