Results 1 to 8 of 8

Thread: How to get a round rectangle (QRegion)

  1. #1

    Default How to get a round rectangle (QRegion)

    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?

  2. #2
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get a round rectangle (QRegion)

    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?

  3. #3
    Join Date
    Dec 2007
    Posts
    14
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get a round rectangle (QRegion)

    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 ?

  4. #4
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get a round rectangle (QRegion)

    You could use
    Qt Code:
    1. QRegion region = QRegion(x,y,w,h,QRegion::Ellipse);
    To copy to clipboard, switch view to plain text mode 
    or you could take a QPainterPath and call toFillPolygon().toPolygon().

  5. #5
    Join Date
    Dec 2007
    Posts
    14
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get a round rectangle (QRegion)

    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..

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get a round rectangle (QRegion)

    Where do u want to draw the rounded rect ??

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

  7. #7
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to get a round rectangle (QRegion)

    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

  8. #8
    Join Date
    Oct 2006
    Posts
    279
    Thanks
    6
    Thanked 40 Times in 39 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get a round rectangle (QRegion)

    Quote Originally Posted by benacler View Post
    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.

Similar Threads

  1. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.