Question

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?

Was it helpful?

Solution

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]

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top