使用QLinearGradient为QProgressBar设置纯色的方法是什么?

huangapple go评论70阅读模式
英文:

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:

使用QLinearGradient为QProgressBar设置纯色的方法是什么?

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"

huangapple
  • 本文由 发表于 2023年4月20日 02:51:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76057936.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定