1

现在我只是想用渐变填充创建一个圆圈:

//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*/);

然而,这一切只是向我展示了一个完全白色的圆圈。我该如何纠正这个问题?

4

2 回答 2

3

我会尽力帮助你,但我英语说得不太好。该死的我也不能同时发布图片......我会在其他网站上发布它们。

当然会是白色的。您使用了错误的坐标。请给我看你的“/* stuff */”变量列表。

你看,如果你为你的小部件设置渐变(在你的情况下它只有一个小区域)你可以在错误的地方画你的椭圆,它肯定是白色的:[见图]
设置渐变坐标正确。例如:

QRadialGradient radial(QPointF(100, 100), 50);
// ...
painter.drawEllipse(50,50,100,100);

[见图]

于 2010-12-04T23:30:33.573 回答
1

在行

radial.setColorAt( 0, Qt::black );

将其更改为行

radial.setColorAt( n, Qt::black );

n 是介于 0 和 1 之间的数字。

于 2012-02-04T15:12:48.140 回答