开发者

Creating QGradient

Right now I am just 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 开发者_如何学Pythonbe 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?


I'll try to help you, but I can't speak english very well. Damn I also can't post images meanwhile... I'll post them on other site.

Sure it will be white. You are using wrong coordinates. Show me your "/* stuff */" variable list, please.

You see, if you set gradient for your widget (in your case its only a little area) you can paint your ellipse in wrong place and it will be surely white: [see pic]
Set Gradients coordinates correct. e.g:

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

[see pic]


In the line

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

change it to the line

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

n being a number between 0 and 1.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜