Metlab
Metlab

Reputation: 69

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?

Upvotes: 0

Views: 655

Answers (2)

i know nothing
i know nothing

Reputation: 1002

If the tab is the first or the last, you can do this:

The first tab:

QTabBar::tab:first
{
    color: blue;
}

The last tab:

QTabBar::tab:last
{
    color: red;
}

Any tab that's not the last (also works for first):

QTabBar::tab:!last
{
    color: orange;
}

Upvotes: 1

Salvo
Salvo

Reputation: 326

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(...);

Upvotes: 1

Related Questions