[Qt-interest] QRegion with rounded rect
Samuel Rødal
sroedal at trolltech.com
Wed Jun 10 13:06:01 CEST 2009
Andre Haupt wrote:
> Hi all,
>
> Maybe i don't see the wood for the trees, but can somebody give me a hint,
> how to construct a QRegion with a shape of a rounded rectangle?
>
> regards,
>
> Andre
I'm not sure why you would want to do this, but one way would be to use
QPainterPath::addRoundedRect, then QPainterPath::toFillPolygon, and
finally the QRegion constructor that takes a polygon.
Something like this:
QPainterPath path;
path.addRoundedRect(QRectF(0, 0, 10, 10), 2, 2);
QRegion region(path.toFillPolygon().toPolygon());
Though in most cases you'd prefer to use the original path instead of
the resulting region as you'd then get nice antialiased edges.
Regards,
Samuel
More information about the Qt-interest-old
mailing list