当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - 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 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?

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: