Define tabs background with stylesheets without changing QWidget?

MARTIN Damien picture MARTIN Damien · Oct 21, 2012 · Viewed 7.7k times · Source

I want to make a very basic GUI: tabs, text area.

But I want to color my tabs and make them always looking the same on MAC, Windows and Linux.

So, I tryed to use a stylesheet:

QTabWidget::pane
{
    border-top: 2px solid #1B1B1B;
    background-color: #262626;
}

QTabWidget::tab-bar
{
    left: 5px;
    alignment: left;
    background: #3E3E3E;
}

QTabBar::tab
{
    background: transparent;
    color: #757575;
    padding: 15px 5px 15px 5px;
}

QTabBar::tab:hover
{
    text-decoration: underline;
}

QTabBar::tab:selected
{
    color: #DEF600;
    background: qlineargradient( x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #262626, stop: 1.0 #3D3D3D );
}

But even if the tabs looks well, there is a problem: The tab pane is still transparent...

I can force a background color by adding:

QWidget
{
    background-color: #262626;
}

But as you know, this change the background color of ALL the widgets, even my QPlainTextEdit that I still want to have a white background. And more annoying, this reset the OS skin and display ugly scrollbars (I really want to keep them as they were).

Is there a way to change the tabs pane background without having to reskin all the components ?

Answer

Ruan picture Ruan · Jul 12, 2017

I had the same problem. I could get it to work with this:

QTabWidget::pane > QWidget {
    background-color: #262626;
}