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

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

How to get solid colors using QLinearGradient when styling QProgressBar?

问题

  1. QProgressBar *b = new QProgressBar();
  2. QString progressStyle = QString("::chunk {"
  3. "background-color: green;"
  4. "}");
  5. b->setStyleSheet(progressStyle);
  6. b->setValue(80);
  7. b->show();
英文:
  1. QProgressBar *b = new QProgressBar();
  2. QString progressStyle = QString("::chunk {"
  3. "background-color: "
  4. "qlineargradient(x0: 0, x2: 1, "
  5. "stop: 0 green, stop: 0.6 green, "
  6. "stop: 0.6 orange, stop: 0.8 orange, "
  7. "stop: 0.8 transparent, stop: 1 transparent"
  8. ")}");
  9. b->setStyleSheet(progressStyle);
  10. b->setValue(80);
  11. 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,以避免颜色范围重叠,从而产生渐变效果。

纯色:

  1. "stop: 0 绿色, stop: 0.6 绿色, "
  2. "stop: 0.60001 橙色, stop: 0.8 橙色, "
  3. "stop: 0.80001 红色, stop: 1 红色"

渐变:

  1. "stop: 0 绿色, stop: 0.6 绿色, "
  2. "stop: 0.6 橙色, stop: 0.8 橙色, "
  3. "stop: 0.8 红色, stop: 1 红色"
英文:

Try adding 0.0001, to avoid color ranges from overlapping, which causes the gradient effect.

Solid colors:

  1. "stop: 0 green, stop: 0.6 green, "
  2. "stop: 0.60001 orange, stop: 0.8 orange, "
  3. "stop: 0.80001 red, stop: 1 red"

Gradient:

  1. "stop: 0 green, stop: 0.6 green, "
  2. "stop: 0.6 orange, stop: 0.8 orange, "
  3. "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:

确定