PDA

View Full Version : How does one draw a 'cut down' ellipse using QPainter



Eos Pengwern
24th July 2012, 00:20
I need to draw a circle within a QPixmap, where the radius of the circle is slightly too big to fit inside the pixmap. The following code draws the circle nicely enough (with a cross and a square as well for good measure):



painter.setViewport(m_originX, m_originY, m_sideX, m_sideY);
painter.setWindow(0, 0, m_pixmap.width(), m_pixmap.height());

painter.drawPixmap(0, 0, m_pixmap);

painter.drawLine(centre.x() - 20, centre.y(), centre.x() + 20, centre.y());
painter.drawLine(centre.x(), centre.y() - 20, centre.x(), centre.y() + 20);
painter.drawRect(centre.x(), centre.y(), squareSize, squareSize);
painter.drawEllipse(centre.x(), centre.y(), circleSize, circleSize););


8036

...except that the parts of the circle outside the QPixmap are also drawn. What I'd really like is to draw only the parts of the circle that lie within the QPixmap, so no lines are visible outside of the image.

Can this be done?

amleto
24th July 2012, 00:33
qpainter.drawArc

wysota
24th July 2012, 00:57
... or clip the painter.

Eos Pengwern
24th July 2012, 02:01
Perfect, that is the solution. Thank you.