当值为16 example?时,可以仅使用QSS设置示例样式。
ui->progresso->setValue(16);使用如下的QSS:
QProgressBar {
//Default QSS
...
}
QProgressBar:value(16) {
background-color: #fc0;
}我的目标是:-当QProgressBar为0时:它将使用background-color: transparent -当QProgressBar大于0时:显示一个灰色条,“块”将是蓝色的-当QProgressBar大于89时:以红色显示“块”。
我可以用QT + C++做到这一点,但是我想知道只有QSS才能做到这一点吗?
就像这样(这段代码不存在,只是一个例子):
QProgressBar {
background-color: gray;
}
QProgressBar:value(0) {
background-color: transparent;
}
QProgressBar::chunk {
background-color: blue;
}
QProgressBar::chunk:minValue(90) {
background-color: red;
}发布于 2015-04-08 13:58:19
我认为在属性选择器的帮助下是可能的,但仅适用于exect值,即:
QProgressBar[value = 16]::chunk{
background-color: red;
}但是您可以在代码中为每个值生成这样的静态工作表
QString styleSheet;
for(int i = 0; i < 101; i++)
{
styleSheet.append(QString("QProgressBar[value = \"%1\"]::chunk{background-color: %2;}").arg(QString::number(i), (i < 17 ? "red" :"blue")));
}
myProgressBar->setStyleSheet(styleSheet);我不会去尝试。这只是一个基于文档的理论。
更新1
Warning: If the value of the Qt property changes after the style sheet has been set, it might be necessary to force a style sheet recomputation. One way to achieve this is to unset the style sheet and set it again. 发布于 2015-04-08 04:36:10
这是不可能的。
唯一有效的扩展名在documentation中,太长了,不能在这里发布。
但是,您可以使用setStyleSheet( )处理QProgressBar的valueChanged( int )信号并相应地设置样式表,但我想您已经知道这一点了。
https://stackoverflow.com/questions/29499735
复制相似问题