使用CSS设置QTabWidget背景样式

时间:2011-11-02 10:18:15

标签: css qt qtabwidget

我希望为活动的QTabWidget选项卡设置自定义背景颜色。不幸的是,我无法弄清楚所需的选择器。 在Linux上,以下hack有效:

QTabWidget::tab > QWidget > QWidget {
        background: #fff;
}

但是在Windows上我必须再使用一个QWidget:

QTabWidget::tab > QWidget > QWidget > QWidget {
        background: #fff;
}

是否有“真正的”解决方案?

1 个答案:

答案 0 :(得分:0)

你必须使用QTabBar而不是QTabWidget。您应该使用的选择器如下:

// Control the tab-bar with respect to the QTabWidget
QTabWidget::tab-bar {
        left: 5px;
}

// Control the look of the tab in general
QTabBar::tab {
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
}

// Control the look of the tab when it is selected
QTabBar::tab:selected
{
        // Add css parameters
}
// Control the look of the tab when hovering over it
QTabBar::tab:hover 
{
        // Add css parameters
}

// Control the look of the tab when it is not selected
QTabBar::tab:!selected
{
        // Add css parameters
}