Question

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?

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top