Mahi
Mahi

Reputation: 21941

Paint QPixmap into a circle?

I can paint a QPixmap just fine:

QPainter painter;
painter.drawPixmap(x, y, w, h, my_pixmap);

And I can also draw a circle with:

painter.drawArc(x, y, w, h, a, alen);

Now I want to combine these two; my pixmap might not always be a circle (=transparent corners) so I can't just paint the whole pixmap on the screen. This means that I need to paint only the center of my pixmap.

Here's an image to make it more clear:

camel

Is this possible?

Upvotes: 0

Views: 2637

Answers (1)

Dan Milburn
Dan Milburn

Reputation: 5738

Yes, you should be able to do this by setting a clip path on the painter. Something like this should work:

QPainterPath path;
path.addEllipse(x, y, w, h);
painter.setClipPath(path);
painter.drawPixmap(x, y, w, h, my_pixmap);

Upvotes: 8

Related Questions