使用样式表更改索引 QTabBar 选项卡的背景
使用 Qt 样式表,是否可以为具有 4 个或更多选项卡的 QTabBar 中的每个选项卡设置不同的背景颜色?
我的 Qt 应用程序在菜单栏下方有 6 个选项卡。我想使用样式表将它们的背景颜色更改为 6 种不同的颜色。
有两个问题似乎阻碍了我:
我只能使用纯样式表语法来设置“第一个”、“中间”和“最后一个”选项卡的样式(因此我说“4 个或更多”选项卡)。
我不认为各个选项卡是我可以访问的 QTabBar 的子小部件。我的想法是,我可以将一个属性附加到我可以在样式表中引用的每个子选项卡。
例如:
// Stylesheet
QTabBar::tab[index="3"] {
background: blue;
}
// Code
QTabBar* bar = new QTabBar;
int index = bar->addTab("Tab 1");
QWidget* tab1; //= ????
tab1->setProperty("index", index);
任何帮助将不胜感激。谢谢。
Using Qt stylesheets, is it possible to set a different background colour for each tab in a QTabBar that has 4 or more tabs?
My Qt application has 6 tabs underneath the menu bar. I'd like to change their background colours to 6 different colours using stylesheets.
2 issues appear to be standing in my way:
I can only style the "first", "middle", and "last" tabs using pure stylesheet syntax (hence why I say "4 or more" tabs).
I don't think the individual tabs are child widgets of the QTabBar that I can access. The idea being that I could then attach a property to each child tab that I could reference in the stylesheet.
For example:
// Stylesheet
QTabBar::tab[index="3"] {
background: blue;
}
// Code
QTabBar* bar = new QTabBar;
int index = bar->addTab("Tab 1");
QWidget* tab1; //= ????
tab1->setProperty("index", index);
Any help would be much appreciated. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
各个选项卡是结构体而不是对象。然后将这些结构用于绘画。有关更多信息,请参阅 Qt 源代码细节。
我对此进行了实验,但我找不到访问直接索引的方法,就像您指出的那样。作为参考,我尝试使用文本、工具提示、whatsThis 等属性,但遗憾的是无法从样式表访问其中任何一个。
恐怕我认为如果不自己子类化和修改绘制事件,您想要做的事情是不可能的。
The individual tabs are structs rather than objects. These structs are then used on painting. See the Qt source for more details.
I've had an experiment with this and I can't find a way to access a direct index, like you indicated. For your reference, I tried using properties such as the text, toolTip, whatsThis but couldn't access any of them from the stylesheets, unfortunately.
I'm afraid I don't think what you want to do is possible without subclassing and modifying the paint events yourself.