英文:
How to get solid colors using QLinearGradient when styling QProgressBar?
问题
QProgressBar *b = new QProgressBar();
QString progressStyle = QString("::chunk {"
"background-color: green;"
"}");
b->setStyleSheet(progressStyle);
b->setValue(80);
b->show();
英文:
QProgressBar *b = new QProgressBar();
QString progressStyle = QString("::chunk {"
"background-color: "
"qlineargradient(x0: 0, x2: 1, "
"stop: 0 green, stop: 0.6 green, "
"stop: 0.6 orange, stop: 0.8 orange, "
"stop: 0.8 transparent, stop: 1 transparent"
")}");
b->setStyleSheet(progressStyle);
b->setValue(80);
b->show();
I'm trying to use solid colors, each color separated from the other, but my code results in gradient colors.
Here's how it looks:
How can I avoid this gradient effect, and achieve the solid colors I need?
答案1
得分: 0
尝试添加 0.0001
,以避免颜色范围重叠,从而产生渐变效果。
纯色:
"stop: 0 绿色, stop: 0.6 绿色, "
"stop: 0.60001 橙色, stop: 0.8 橙色, "
"stop: 0.80001 红色, stop: 1 红色"
渐变:
"stop: 0 绿色, stop: 0.6 绿色, "
"stop: 0.6 橙色, stop: 0.8 橙色, "
"stop: 0.8 红色, stop: 1 红色"
英文:
Try adding 0.0001
, to avoid color ranges from overlapping, which causes the gradient effect.
Solid colors:
"stop: 0 green, stop: 0.6 green, "
"stop: 0.60001 orange, stop: 0.8 orange, "
"stop: 0.80001 red, stop: 1 red"
Gradient:
"stop: 0 green, stop: 0.6 green, "
"stop: 0.6 orange, stop: 0.8 orange, "
"stop: 0.8 red, stop: 1 red"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论