【问题标题】:Styling QTabWidget background with CSS使用 CSS 设计 QTabWidget 背景
【发布时间】:2011-11-02 10:18:15
【问题描述】:

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

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

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

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

有“真正的”解决方案吗?

【问题讨论】:

    标签: css qt qtabwidget


    【解决方案1】:

    你必须使用 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
    }
    

    【讨论】:

    • 不幸的是它没有用。我进一步诊断了这个问题。我插入一个 QScrollArea 作为带有所需内容的选项卡。如果我忽略滚动区域,您的解决方案将起作用。在 SA 本身上设置背景不起作用。
    • 您要更改选项卡的背景还是显示的小部件的背景?
    • 最好两者都有——以防不使用滚动区域。
    • QScrollArea *scrollArea = new QScrollArea(); scrollArea->setWidgetResizable(true); scrollArea->setFrameShape(QFrame::NoFrame); scrollArea->setWidget(editorWidget); mLeafWidget->addTab(scrollArea, tabLabel);
    • 你想在每次用户选择标签时改变scrollArea的背景颜色?
    猜你喜欢
    • 2019-06-24
    • 1970-01-01
    • 2013-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多