如何创建 QRadialGradient
我正在尝试创建一个带有渐变填充的圆圈:
//I want the center to be at 10, 10 in the circle and the radius to be 50 pixels
QRadialGradient radial(QPointF(10, 10), 50);
radial.setColorAt(0, Qt::black); //I want the center to be black
radial.setColorAt(1, Qt::white); //I want the sides to be white
painter.setBrush(QBrush(radial));
painter.drawEllipse(/*stuff*/);
但是,所有这些完成的只是向我显示一个完全白色的圆圈。我该如何纠正这个问题?
I am trying to create a circle with a gradient fill:
//I want the center to be at 10, 10 in the circle and the radius to be 50 pixels
QRadialGradient radial(QPointF(10, 10), 50);
radial.setColorAt(0, Qt::black); //I want the center to be black
radial.setColorAt(1, Qt::white); //I want the sides to be white
painter.setBrush(QBrush(radial));
painter.drawEllipse(/*stuff*/);
However, all this accomplishes is to show me a totally white circle. How can I rectify this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它将是白色的,因为您使用了错误的坐标。
如果您为小部件设置渐变(在您的情况下,它只是一个小区域),您可以在错误的位置绘制椭圆,并且它肯定会是白色:
正确设置渐变的坐标。例如:
It will be white because you are using the wrong coordinates.
If you set the gradient for your widget (in your case it's only a small area), you can paint your ellipse in the wrong place, and it will be surely white:
Set the gradient's coordinates correctly. e.g:
更改
为:
n
是 0 到 1 之间的数字。Change:
To:
n
being a number between 0 and 1.