设置QTabWidget的Tab部分的颜色 [英] Setting color of Tab part of QTabWidget

查看:1757
本文介绍了设置QTabWidget的Tab部分的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我更改QTabWidget的背景颜色时,该窗口小部件的选项卡部分不会更改颜色.在网上寻找似乎不是一种简单的方法来设置此颜色.有建议吗?

When I change the background color of the QTabWidget, the tab part of the widget doesn't change colors. Looking online there doesn't seem to be a simple way to set this color. Suggestions?

推荐答案

您可以使用Qt的样式表来做到这一点.来自文档:

You can do that using Qt's style sheets. From the docs:

/* Style the tab using the tab sub-control. Note that
    it reads QTabBar _not_ QTabWidget */
QTabBar::tab  {
    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                                stop: 0 #E1E1E1, stop: 0.4 #DDDDDD,
                                stop: 0.5 #D8D8D8, stop: 1.0 #D3D3D3);
    border: 2px solid #C4C4C3;
    border-bottom-color: #C2C7CB; /* same as the pane color */
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    min-width: 8ex;
    padding: 2px;
}

将所需的QSS定义为字符串后,然后使用

Once you've defined the QSS of interest as a string, you then set the QSS on the widget in question using the setStyleSheet method. If you're only interested in setting the background color, a simple stylesheet will probably suffice:

yourQTabWidget->setStyleSheet("QTabBar::tab { background-color: #FF0000; }");

-stylesheet命令行选项也可用,可用于设置应用程序样式.然后,在行为良好的应用程序中,您应该能够执行以下操作:

A -stylesheet command line option is also available and can be used to style the application. In a well-behaving application, you should then be able to do the following:

yourQtProgram.exe -stylesheet /path/to/your/stylesheet.qss

这篇关于设置QTabWidget的Tab部分的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆