Search code examples
qtqt5qtstylesheets

How to set qss style for two different tab bars of two QTabWidget?


Is there any way to set two different qss style rules for two QTabWidgets tabs. I can set style rule for all tab like this:

QTabBar::tab {...}

But it will set the stye for all tab bars of QTabWidgets

How to set QTabBar tab style for certain instance of QTabWidget?


Solution

  • You can use the QObject::setObjectName(const QString &name) function to give every QTabWidget a different name and then set the style for a particular QTabWidget using its name:

    QTabWidget#tabname {...}
    

    Alternatively you can do the same on the code side without using the setObjectName() function but setting the stylesheet directly to the widget itself like this:

    ui->tabWidget->setStyleSheet(...);