Results 1 to 2 of 2

Thread: Qt drawing a filled rounded rectangle with border

  1. #1
    Join Date
    May 2014
    Posts
    136
    Thanks
    72
    Qt products
    Qt3 Qt4 PyQt3 PyQt4
    Platforms
    MacOS X Windows

    Default Qt drawing a filled rounded rectangle with border

    I want to draw a rectangle with rounded corners (border radius same for all 4 corners) with a specific color filing the entire rectangle, and a separate border color (say border is 1 px wide).

    From my observation, Qt provides three methods - fillRect and drawRect and drawRoundedRect. There is, however, no method like fillRoundedRect. Which means that I can draw a rounded rectangle but it won't be filled with the color I want.

    How do I do it? And also, I read that due to some aliasing problems, the corners are often rendered equal. How do I set it as equal for all four? Will painter.setRenderHint(QPainter::Antialiasing) suffice? Or do I have to do anything else?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt drawing a filled rounded rectangle with border

    The fillXYZ methods are just for convenience, to require less calls for the most common area types that need filling.

    You can fill any area type by setting a brush on the painter before calling the respective draw function.

    The pen decides the color of the border, the brush for the filling.

    Cheers,
    _

Similar Threads

  1. QScrollArea with rounded border gets over-painted
    By Scint in forum Qt Programming
    Replies: 0
    Last Post: 23rd June 2014, 22:13
  2. Replies: 6
    Last Post: 16th April 2013, 16:13
  3. 3D Border Style for Rectangle in QML
    By tauseef in forum Qt Programming
    Replies: 1
    Last Post: 2nd April 2013, 06:10
  4. Drawing of Rectangle which is rounded from only two side
    By vinayptl in forum Qt Programming
    Replies: 1
    Last Post: 5th March 2013, 07:03
  5. Replies: 2
    Last Post: 5th July 2008, 19:35

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.