Change the background of indexed QTabBar tabs using style sheets

Using Qt's style sheets, is it possible to set a different background color for each tab in a QTabBar with 4 or more tabs?

My Qt application has 6 tabs under the menu bar. I would like to change their background colors to 6 different colors using style sheets.

There seem to be 2 questions in my way:

  • I can only stylize the tabs "first", "middle" and "last", using the syntax of a clean style sheet (from here I say "4 or more" tabs).

  • I don’t think the individual tabs are child QTabBar widgets that I can access. The idea was that I could then bind a property to each child tab that I could reference in the stylesheet.

For instance:

// Stylesheet
QTabBar::tab[index="3"] {
   background: blue;
}

// Code
QTabBar* bar = new QTabBar;
int index = bar->addTab("Tab 1");
QWidget* tab1; //= ????
tab1->setProperty("index", index);

. .

+3
1

, . . . Qt source.

, , . , , toolTip, whatsThis, , .

, , , .

+5

Source: https://habr.com/ru/post/1733559/


All Articles