How to draw rounded corners with QPainter::drawPolyLine

I'm trying to create a custom container widget at the moment using QGroupBox as a base and drawing the new frame in the paint event, which is all working fine using drawPolyLine to create it, but I'd like to draw the frame with rounded corners. Has anyone come across a way to do it with drawPolyLine or would I need to rewrite my code to implement them?

Answers


When it comes to custom flexible shapes, QPainterPath is the most powerful class of them all. You could for example use QPainterPath::arcTo() in order to draw single rounded corners, though painting the full shape might require some math.

Another possibility is defining single shapes and merging them using intersected() or subtracted(), as already suggested by cbamber85 in the comments.


QPen has a "Cap Style" option of Qt::RoundCap which could result in rounded corners depending on pen width.


Need Your Help

NSDateFormatter - does not respect 12/24 hour (am/pm) system setting in some circumstances

iphone nsdateformatter

I want to output a date (that has relative dates, e.g. Today, Yesterday etc.) and time (respecting the 12/24 hours setting on the iOS device) E.g.

Semantic HTML for confirmation, error and warnings messages

html html5 semantic-markup error-messaging

What are people's opinions on semantic HTML for confirmation, error and warnings messages?