1
votes

I am trying to draw a rectangle with big stroke width(set by a QPen) and QPainter is drawing the rectangle but all of the corners are a little cut out, not as sharp as they ought to be. Here is an image: https://i.imgur.com/WhUWLwc.png

I'm drawing it on top of a QWidget using this code:

m_painter.drawRect(upLeftX, upLeftY, downRightX - upLeftX, downRightY - upLeftY);
1
Take a look at QPen::setJoinStyle. You need Qt::MiterJoin.G.M.
Thanks, I don't know why they thought this to be the default behaviour. You can submit an answer if you want so I can accept it.Rokner

1 Answers

1
votes

Moved from comment.

You can set the pen's join style easily using QPen::setJoinStyle. To modify the pen currently in use by the QPainter use something like...

QPen pen = m_painter.pen();
pen.setJoinStyle(Qt::MiterJoin);
m_painter.setPen(pen);