Results 1 to 2 of 2

Thread: Optimizing the painting on a custom QGraphicsItem

  1. #1
    Join Date
    Feb 2012
    Posts
    12
    Qt products
    Platforms
    Unix/X11 Windows

    Question Optimizing the painting on a custom QGraphicsItem

    I have a custom QGraphicsItem which has a QPainterPath as member.
    As the mouse is dragged, the movement is traced onto this path. The paint() method in the QGrahicsItem draws the whole path everytime a new point is added to the path.

    The purpose of implementing this is, the whole path is drawn to an image when the mouse is released (The image needs to be free for other drawing as long as possible, so can't directly draw on it).

    The issue here is, as the path gets longer, the updating of graphics on QGraphicsScene gets visibly slower (while mouse is dragged for a long time).

    Is there a way to optimize and speed up the paint() method in this case, while keeping the path info which needs to be directly drawn to an image?

  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: Optimizing the painting on a custom QGraphicsItem

    You can draw to a temporary pixmap and only update the pixmap with the last created segment of the path. Then when the user releases the mouse, either draw the pixmap to the destination image or restroke the path directly.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Painting the mouse trace in a QGraphicsItem
    By xtraction in forum Qt Programming
    Replies: 2
    Last Post: 9th February 2013, 11:08
  2. Painting problem for QGraphicsItem
    By vivekpurohit in forum Qt Programming
    Replies: 1
    Last Post: 9th August 2011, 10:55
  3. specific painting for just one QGraphicsItem
    By jano_alex_es in forum Qt Programming
    Replies: 1
    Last Post: 24th March 2011, 02:12
  4. QGraphicsItem - painting problem for zoomin
    By nileshsince1980 in forum Qt Programming
    Replies: 0
    Last Post: 26th March 2010, 10:02
  5. Force the painting of a QGraphicsItem
    By fabietto in forum Qt Programming
    Replies: 3
    Last Post: 2nd July 2007, 22:28

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.