Results 1 to 4 of 4

Thread: QPainterPath drawing problem

  1. #1
    Join Date
    Jan 2006
    Location
    Russia
    Posts
    16
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QPainterPath drawing problem

    Why does QPainterPath contains so few methods for drawing graphic primitives? How can I draw rounded rect on QPainterPath?

    Let me describe what I want - I have some graphic primitives like rounded rect and want to draw them as a background for QGraphicsView, so I decided to draw them once to QPainterPath and draw it to view in QGraphicsView::drawBackground, but seems that QPainterPath miss methods I need (drawRoundRect for example).

  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: QPainterPath drawing problem

    You can make a round rectangle by adding a rectangle and then substracting the corners by adding arcs. Just look at the QPainterPath docs, there is an example there that shows an object with removed interiors. Another possibility is to compose the path from four lines and four arcs and making sure the path is closed.

  3. #3
    Join Date
    Jan 2006
    Location
    Russia
    Posts
    16
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPainterPath drawing problem

    no, I can't use rect because I need several rects with variable roundedness (from minimum to maximum), I can't "emulate" them with rect or arcs.

  4. #4
    Join Date
    Jan 2006
    Posts
    128
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QPainterPath drawing problem

    Draw them yourself?

    Qt Code:
    1. const qreal top = XXX;
    2. const qreal left = XXX;
    3. const qreal bottom = XXX;
    4. const qreal right = XXX;
    5.  
    6. const qreal xMaxRoundness = XXX;
    7. const qreal yMaxRoundness = XXX;
    8.  
    9. const qreal roundnessSizeX = qMin((qAbs(right - left) / 2.0), xMaxRoundness);
    10. const qreal roundnessSizeY = qMin((qAbs(top - bottom) / 2.0), yMaxRoundness);
    11.  
    12. QPainterPath roundedRect(QPointF(left, top - roundnessSizeY));
    13. roundedRect.arcTo(left, top,
    14. roundnessSizeX * 2.0, roundnessSizeY * 2.0,
    15. 180.0, -90.0);
    16. roundedRect.arcTo(right - roundnessSizeX * 2.0, top,
    17. roundnessSizeX * 2.0, roundnessSizeY * 2.0,
    18. 90.0, -90.0);
    19. roundedRect.arcTo(right - roundnessSizeX * 2.0, bottom - roundnessSizeY * 2.0,
    20. roundnessSizeX * 2.0, roundnessSizeY * 2.0,
    21. 0.0 , -90.0);
    22. roundedRect.arcTo(leftPosition, bottom - roundnessSizeY * 2.0,
    23. roundnessSizeX * 2.0, roundnessSizeY * 2.0,
    24. -90.0, -90.0);
    25. roundedRect.closeSubpath();
    To copy to clipboard, switch view to plain text mode 
    Last edited by camel; 17th January 2007 at 13:42. Reason: reformatted to look better

Similar Threads

  1. qevent problem
    By amulya in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2006, 11:51
  2. drawing problem
    By boss_bhat in forum Newbie
    Replies: 1
    Last Post: 20th September 2006, 10:49
  3. Facing problem with Q3Canvas
    By jnana in forum Qt Programming
    Replies: 3
    Last Post: 6th May 2006, 07:00
  4. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.