作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前有一个具有以下样式表的 QToolBar
QToolBox::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-radius: 3px;
color: darkgray;
width: 70px;
}
QToolButton { /* all types of tool button */
border: 2px solid #8f8f91;
border-radius: 6px;
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #f6f7fa, stop: 1 #dadbde);
}
QToolButton[popupMode="1"] { /* only for MenuButtonPopup */
padding-right: 30px; /* make way for the popup button */
}
QToolButton:pressed {
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #dadbde, stop: 1 #f6f7fa);
}
/* the subcontrols below are used only in the MenuButtonPopup mode */
QToolButton::menu-button {
border: 2px solid gray;
border-top-right-radius: 6px;
border-bottom-right-radius: 6px;
/* 16px width + 4px for border = 20px allocated above */
width: 30px;
}
现在,上述样式表的问题是 QToolButton
标记应用于我添加到 QtoolBar 的每个工具按钮。无论如何限制 tis 设计的应用到我动态添加的某些 QToolButton
。样式表在设计时添加到 QToolBar ?
最佳答案
您可以使用实例化 QToolButton 的对象名称。在 QStyleSheet 中,您可以使用 #ObjectName 定位 QtWidget 继承类的特定实例。
来源中的例子:
QWidget *pWidget = new QWidget(parent);
pWidget->setObjectName("myWidget");
qss 中的示例:
QWidget {
background-color: red;
}
#myWidget {
background-color: green;
}
对于对象名称设置为“myWidget”的小部件,背景将为绿色,对于所有其他小部件,背景将为红色。
如果您也动态更新您的样式表,您最终将需要 polish() 您的小部件。为此,请查看 Qt doc : polish()
关于c++ - Qt : How to make a dynamically added item not comply to style sheet set at design time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20299257/
我是一名优秀的程序员,十分优秀!