Results 1 to 9 of 9

Thread: How to draw a filled round rect?

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default How to draw a filled round rect?

    Hi,

    As the subject says.
    I can find the normal fillRect() function, but not for a round rect...
    But the docs say:
    void QPainter::drawRoundRect ( const QRectF & r, int xRnd = 25, int yRnd = 25 )

    Draws a rectangle r with rounded corners.

    The xRnd and yRnd arguments specify how rounded the corners should be. 0 is angled corners, 99 is maximum roundedness.

    A filled rectangle has a size of r.size(). A stroked rectangle has a size of r.size() plus the pen width.
    Help?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to draw a filled round rect?

    Did you set a brush (QBrush) for your painter?

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to draw a filled round rect?

    Thanks, so it fills automatically when there is a brush deifned, which means I need to excplicitly set brush "on" and "off" if I want just the outline or filled round rect...
    Why is it done like that for round rect, and for normal rect they offered a fillRect() methods?
    Hmm...

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to draw a filled round rect?

    Because fillRect is not for drawing rectangles. You should use QPainter::drawRect() for that. QPainter::fillRect() is for filling areas (and by the way, it takes a QBrush as its argument).

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to draw a filled round rect?

    I know, fill rect FILLS rectangles.
    Which means you have a method for drawing rects and a method for filling them.
    But not so for round rects, where you only have one method for drawing which also fills it if the brush is set.
    A drawRect will not fill a rect even if brush is set.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to draw a filled round rect?

    Quote Originally Posted by high_flyer
    I know, fill rect FILLS rectangles.
    It is used for filling areas in general.

    But not so for round rects, where you only have one method for drawing which also fills it if the brush is set.
    Like for all other shapes.

    A drawRect will not fill a rect even if brush is set.
    Are you sure? Try running the code from attachment.
    Attached Files Attached Files

  7. #7
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to draw a filled round rect?

    It is used for filling areas in general.
    I am not sure what do you mean by that...
    Filling areas that are not rectangles as well?
    How so?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to draw a filled round rect?

    Because there are methods for filling paths. I think these are only convienience methods. There are probably implemented using drawRect and drawPath with null pens. You can check that yourself in the source code. In short, the difference between drawRect and fillRect is that the latter doesn't use the pen.

  9. #9
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to draw a filled round rect?

    Thanks!

    (this text is only in order to allow me to post a one word post )

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.