PDA

View Full Version : How to get a round rectangle (QRegion)



quzcFroal
29th May 2008, 11:50
QRegion class can only create Rectangle and Ellipse region, but Ellipse region is aliasing.
QPainterPath class can set "Antialiasing" flag, and can create a round rectangle without aliasing easily, but it can NOT convert to a QRegion. Now I want to get a round rectangle which is a QRegion, it's difficult, to me.

So the question is also like this : How to get a Antialiasing Ellipse which is a QRegion?

spud
29th May 2008, 13:29
I'm not sure if you really mean antialiasing or "with floating point precision". Anyway, QRegion won't help you in either case, since it is essentially a pixel mask.

There might be a solution to your problem if you tell us what you need it for. Are you using it for painting, or for setting the shape of a top level window?

benacler
1st June 2008, 03:52
I made a rounded shape (my purpose was skinning top level windows) by additing 4 small radius circles and four border bars with the same width of the circle radius to a window region smaller than the borders width....

Seems complex but it works actually... Is there a faster way ?

spud
1st June 2008, 18:30
You could use

QRegion region = QRegion(x,y,w,h,QRegion::Ellipse);
or you could take a QPainterPath and call toFillPolygon().toPolygon().

benacler
2nd June 2008, 02:21
the QRegion::Ellipe creates an ellipse, while in my case I need to make something like a rounded box :)
Maybe a rounded rect in a PainterPath seems more appropriate but I don't get how you convert a path to a mask exactly....the toPolygon() returns a QPolygon while you need a QRegion or QBitmap to apply a mask..

aamer4yu
2nd June 2008, 11:14
Where do u want to draw the rounded rect ??

Take a look at QPainter::drawRoundedRect . Hope it helps :)

pherthyl
2nd June 2008, 17:24
I remember that it is possible somehow to construct regions manually to make rounded rects and such. However I now no longer can remember how exactly to do it. Another alternative is to paint a rounded rect onto a QBitmap and then use that as the argument to QWidget::setMask

spud
2nd June 2008, 22:14
the QRegion::Ellipe creates an ellipse, while in my case I need to make something like a rounded box :)
Maybe a rounded rect in a PainterPath seems more appropriate but I don't get how you convert a path to a mask exactly....the toPolygon() returns a QPolygon while you need a QRegion or QBitmap to apply a mask..
Check out the QRegion constructor which takes a QPolygon argument.