Results 1 to 5 of 5

Thread: QPainter::drawRoundedRect() drawing uneven corners

  1. #1
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default QPainter::drawRoundedRect() drawing uneven corners


    (Scaled x3)

    I'm trying to draw a rounded rect, where the corners are rounded the same as each other. As you can see in the image above, mine keep coming out where the upper-left corner is correct, the lower-right corner is wrong, and the other two are somewhere in-between.

    I'm calling the function like this:
    Qt Code:
    1. painter->drawRoundedRect(...blah..., 7.0f, 7.0f);
    To copy to clipboard, switch view to plain text mode 

    Clearly I don't understand how QPainter::drawRoundedRect() works. ( http://doc.qt.nokia.com/latest/qpain...rawRoundedRect )

    Why are my corners uneven?

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: QPainter::drawRoundedRect() drawing uneven corners

    Your corners are uneven probably because of:
    * Drawing the corners having a small radius compared to the screen resolution at positions that map differently into the screen pixels
    * The shapes being drawn using idealistic algebra which doesn't take the into account the problems of low resolution screens & small graphics

    Of course Qt could and should do a better job here.

    (You should scale screen grabs at an even ratio (2 x, 4x etc... instead of 3 x) so that they can be scaled back pixelwise exactly.)

  3. The following user says thank you to mvuori for this useful post:

    ComServant (20th July 2011)

  4. #3
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QPainter::drawRoundedRect() drawing uneven corners

    So is there any way around that? Buttons and things drawn by Qt don't suffer from the same problem, and their corners are drawn relatively tiny.

    How can I make the corners of my rounded rects uniform?

  5. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: QPainter::drawRoundedRect() drawing uneven corners

    It is very much possible to draw a symmetrical rounded rectangle, It's strange to observe that QPainter::drawRoundedRect() algorithm to draw is not capable to do so. It draws ok, when pen width on 1, for higher pen widths it deviates. Also looks like rounded rectangle is drawn using a painter paths using qreal point, that means that all four corners are drawn individually, even though their radius is same, because of real number calculations, the final bitmap may differ.

    Any way, you can try using anti-aliasing to make it look better to some extent (painter.setRenderHint(QPainter::Antialiasing)

  6. The following user says thank you to Santosh Reddy for this useful post:

    ComServant (20th July 2011)

  7. #5
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QPainter::drawRoundedRect() drawing uneven corners

    Thanks, antialiasing makes it look loads better. I did notice that single-pixel pen widths looked better also, but I'd prefer a thicker border in this case.

    I appreciate the help!

Similar Threads

  1. Combining QPainter and WinAPI drawing
    By kkk777kkk in forum Newbie
    Replies: 2
    Last Post: 6th July 2011, 14:16
  2. QPainter immediate drawing outside paint event
    By sfcheng77 in forum Qt Programming
    Replies: 1
    Last Post: 23rd February 2011, 06:39
  3. Text drawing with QPainter
    By Rambobino in forum Qt Programming
    Replies: 2
    Last Post: 1st November 2010, 17:26
  4. QPainter and complex drawing : advices
    By toutarrive in forum Qt Programming
    Replies: 0
    Last Post: 18th November 2009, 10:51
  5. QPainter - drawRoundedRect Question
    By ChrisReath in forum Qt Programming
    Replies: 2
    Last Post: 14th May 2008, 14:14

Tags for this Thread

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.