Results 1 to 20 of 23

Thread: how to prevent qgraphicsitem repaint while mouse move on it

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Posts
    38
    Thanks
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default how to prevent qgraphicsitem repaint while mouse move on it

    Hi,everyone. I have found a problem which troubled me for a long time:
    That when i move mouse, the class which inherit from qgraphicsitem will be repainted? And this have obviously slower my graph(which drawed in the class inherits from qgraphicsItem) .
    how can i prevent when the mouse move ,and the item won't be repainted?
    help me soonly ! really need your help . thank you.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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 prevent qgraphicsitem repaint while mouse move on it

    Quote Originally Posted by christina123y View Post
    That when i move mouse, the class which inherit from qgraphicsitem will be repainted?
    Yes, it might be.

    And this have obviously slower my graph(which drawed in the class inherits from qgraphicsItem) .
    how can i prevent when the mouse move ,and the item won't be repainted?
    There are at least three different ways to handle your situation. One possibility is to render contents of your item to a pixmap and only update the pixmap when you're not moving the item and if you are then render the old contents. Second possibility is to enable one of the caching modes for the item which does essentially more or less the same. I forgot the third solution
    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.


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

    christina123y (9th April 2009)

  4. #3
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to prevent qgraphicsitem repaint while mouse move on it

    Quote Originally Posted by wysota View Post
    There are at least three different ways to handle your situation. One possibility is to render contents of your item to a pixmap and only update the pixmap when you're not moving the item and if you are then render the old contents. Second possibility is to enable one of the caching modes for the item which does essentially more or less the same. I forgot the third solution
    I am having the same problem, that the QGraphicsItem will do unnecessary paint when the window lose/gain focus or on a mouse movement, even though there is no actual new exposure event occurring.

    I think this is a bug that Qt should fix, rather than asking application developers to find a workaround...

  5. The following user says thank you to lni for this useful post:

    christina123y (9th April 2009)

  6. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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 prevent qgraphicsitem repaint while mouse move on it

    Quote Originally Posted by lni View Post
    I am having the same problem, that the QGraphicsItem will do unnecessary paint when the window lose/gain focus or on a mouse movement, even though there is no actual new exposure event occurring.


    I think this is a bug that Qt should fix, rather than asking application developers to find a workaround...
    This time I won't enter this flamewar. I don't agree with you but you have the right to have a different opinion. I can only say "read the docs".
    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.


  7. #5
    Join Date
    Feb 2009
    Posts
    38
    Thanks
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to prevent qgraphicsitem repaint while mouse move on it

    Quote Originally Posted by lni View Post
    I am having the same problem, that the QGraphicsItem will do unnecessary paint when the window lose/gain focus or on a mouse movement, even though there is no actual new exposure event occurring.

    I think this is a bug that Qt should fix, rather than asking application developers to find a workaround...
    hi, i have resolve this problem through the second method suggested by wysota. i called setCacheMode(QGraphicsItem::ItemCoordinateCache,QS ize(width(),height())) for the qgraphicsitem. you can have a try.

  8. #6
    Join Date
    Feb 2009
    Posts
    38
    Thanks
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to prevent qgraphicsitem repaint while mouse move on it

    Quote Originally Posted by wysota View Post
    Yes, it might be.



    There are at least three different ways to handle your situation. One possibility is to render contents of your item to a pixmap and only update the pixmap when you're not moving the item and if you are then render the old contents. Second possibility is to enable one of the caching modes for the item which does essentially more or less the same. I forgot the third solution

    Hi, I have solved this problem through your second method.
    i am very grategful for your help. But i fill confused with the first method.Can you explain for me more specifically? when the size of pixmap is in line with the size of the qgraphicsItem, while update the pixmap whether the qgraphicsItem will also being updated?

    i'm looking forwad to hearing from you soonly.

  9. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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 prevent qgraphicsitem repaint while mouse move on it

    Quote Originally Posted by christina123y View Post
    But i fill confused with the first method.Can you explain for me more specifically? when the size of pixmap is in line with the size of the qgraphicsItem, while update the pixmap whether the qgraphicsItem will also being updated?
    The first method is more or less the same as the second one only that it is your responsibility to update the pixmap. The approach is described here in Qt Quarterly: http://doc.trolltech.com/qq/qq06-fli...oublebuffering

    Qt3 didn't have double buffering capabilities so it had to be emulated using a pixmap.
    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.


  10. The following user says thank you to wysota for this useful post:

    christina123y (9th April 2009)

  11. #8
    Join Date
    Feb 2009
    Posts
    38
    Thanks
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Smile Re: how to prevent qgraphicsitem repaint while mouse move on it

    Quote Originally Posted by wysota View Post
    The first method is more or less the same as the second one only that it is your responsibility to update the pixmap. The approach is described here in Qt Quarterly: http://doc.trolltech.com/qq/qq06-fli...oublebuffering

    Qt3 didn't have double buffering capabilities so it had to be emulated using a pixmap.
    I have read the reference you provide for me. and i comprehand more about the first method you suggest. and i will have a try. Thank you. any success or question will go shares.

  12. #9
    Join Date
    Feb 2009
    Posts
    38
    Thanks
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: how to prevent qgraphicsitem repaint while mouse move on it

    Quote Originally Posted by wysota View Post
    The first method is more or less the same as the second one only that it is your responsibility to update the pixmap. The approach is described here in Qt Quarterly: http://doc.trolltech.com/qq/qq06-fli...oublebuffering

    Qt3 didn't have double buffering capabilities so it had to be emulated using a pixmap.
    Hi, i still have a question about the second method you suggested me.

    i use setCacheMode() function for my item. it really didn't make my item to repaint when the mouse move on it.
    Howerver when i zoom in the item , and the zoom percentage is set larger ( such as 3) or when i zoom in the graph for more times , then when the mouse move on the item, my item now begin to repaint. and i have a try ,when my zoom in percentage is 1.4*1.4, then i zoom in for two times won't make my item to repaint, when i zoom in for one more time , my item begin to repaint when the mouse move on it.
    i also have set the right size of setCacheMode() when the item is scaled, this means that setCacheMode(CacheMode mode,QSize size) 's size is the same size of my item's boundingRect.
    why ?

    ......./
    and now i have found that qt has set limit to the size of cache,the default settings is 1024 kilobytes. when my graph is zoom in larger than this (1M), it now begin to call paint() to repaint.
    and i also have tried to set the QSize is 1M, but it still didn't work, and this make my graph distortion. how can i resolve this problem.
    wish your help soon!
    I'm very appreciate for your help!
    Last edited by christina123y; 10th April 2009 at 07:44.

  13. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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 prevent qgraphicsitem repaint while mouse move on it

    Which cache mode did you use? The limit you mention is set on QPixmapCache. You can modify it using QPixmapCache::setCacheLimit().
    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.


  14. The following user says thank you to wysota for this useful post:

    christina123y (10th April 2009)

  15. #11
    Join Date
    Feb 2009
    Posts
    38
    Thanks
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to prevent qgraphicsitem repaint while mouse move on it

    Quote Originally Posted by wysota View Post
    Which cache mode did you use? The limit you mention is set on QPixmapCache. You can modify it using QPixmapCache::setCacheLimit().
    i use qgraphicsitem 's cache mode ----QGraphicsItem::ItemCoordinateCache.
    this method really improve speed of drawing graph.
    how can i resolve the problem i encountered(don't through setCacheLimit() , any other resolvent?). how can i use QGraphicsItem::setCacheMode() and when the graph is zoom in to some extent( then when the mouse move on this item, won't make my item to repaint ), but don't through setCacheLimit() , because anyway it seems unpratical.
    wish your help again!
    great thanks for your help!

  16. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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 prevent qgraphicsitem repaint while mouse move on it

    I have trouble understanding you. What seems impractical? If you want the item to be cached you have to make sure it fits in the cache or you will either lose quality or speed. You can use the other cache mode - DeviceCoordinateCache, maybe that fits your usecase more than ItemCoordinateCache.
    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.


  17. The following user says thank you to wysota for this useful post:

    christina123y (11th April 2009)

  18. #13
    Join Date
    Feb 2009
    Posts
    38
    Thanks
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to prevent qgraphicsitem repaint while mouse move on it

    Quote Originally Posted by wysota View Post
    I have trouble understanding you. What seems impractical? If you want the item to be cached you have to make sure it fits in the cache or you will either lose quality or speed. You can use the other cache mode - DeviceCoordinateCache, maybe that fits your usecase more than ItemCoordinateCache.
    Hi, i have already tried DeviceCoordinateCache cache mode ,but it still didn't work for me.
    And i have look up the other thread ---
    http://www.qtcentre.org/forum/f-qtop...tes-16213.html
    and i have tried setViewportUpdateMode(), still can't help for me.

    and i fill puzzled with what you said on #4(Check the boundingRect() for both items. For instance using QRectF::intersects(). Just remember to map those rects to scene coordinates first. It's the bounding rects that may intersect, not the shapes themselves),
    would this helpwith me?

    or any other solutions to this problem? thank you

    and when i zoom in the graph to some extent, the scrollbar on the qgraphicsview can be dragged very slowly., the graph is repainted , and there is serious time delay.
    Last edited by christina123y; 11th April 2009 at 06:06.

  19. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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 prevent qgraphicsitem repaint while mouse move on it

    You have to be aware you can't reduce the number of repaints to zero. Eventually your items will have to be repainted. And preventing complex repaints doesn't cause any repaints to stop - the item is still repainted but from the cache and not using complex drawing mechanisms. But if the area covered by the item becomes very big, repainting from cache might get slow as well. Tell me why exactly DeviceCoordinateCache doesn't work for you and what was wrong in using ItemCoordinateCache. Also try setting the viewport of the view to QGLWidget so that hardware acceleration kicks in.
    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.


  20. The following user says thank you to wysota for this useful post:

    christina123y (11th April 2009)

  21. #15
    Join Date
    Feb 2009
    Posts
    38
    Thanks
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to prevent qgraphicsitem repaint while mouse move on it

    Quote Originally Posted by wysota View Post
    You have to be aware you can't reduce the number of repaints to zero. Eventually your items will have to be repainted. And preventing complex repaints doesn't cause any repaints to stop - the item is still repainted but from the cache and not using complex drawing mechanisms. But if the area covered by the item becomes very big, repainting from cache might get slow as well. Tell me why exactly DeviceCoordinateCache doesn't work for you and what was wrong in using ItemCoordinateCache. Also try setting the viewport of the view to QGLWidget so that hardware acceleration kicks in.
    First, the problem with ItemCoordinateCache mode is that --------when my item need to draw a large amount of data (such as hundreds of thousands points or millions points),this make my graph look very density, my item's boundingrect change as zoom in proportion, and i update cache with new graph(after scale), however, if i zoom in my graph to some extent(which make the size of graph is larger than the cache), then the cache's graph is unuseless , and when the mouse move on the item, the graph is repaint too slowly ,event i can't drag the scrollbar on the graphicsview.
    and i can't set the size of cache absoluteness , because the data counts is uncertained (for this i also can't constraint the counts of zoom in ).

    Second, i have tried DeviceCoordinateCache mode ,and the problem is the same as i use ItemCoordinateCache .

    Third, i didn't catch what you say to set the viewport of the view to QGLWidget clealy.

    and i know that it can't avoid repaint of item, what i need is just to enhance the speed of repaint when the mouse is move on the qgraphicsitem when the item is zoomed in to some extent.

    most grateful for your reply.

Similar Threads

  1. Replies: 9
    Last Post: 22nd June 2008, 22:26
  2. Replies: 4
    Last Post: 3rd March 2008, 22:15
  3. Mouse Move Event
    By merry in forum Newbie
    Replies: 5
    Last Post: 3rd June 2007, 06:26
  4. Move Rectangle on mouse Move
    By vermarajeev in forum Qt Programming
    Replies: 24
    Last Post: 14th May 2007, 05:34
  5. how to display full tree item name on mouse move ?
    By rajesh in forum Qt Programming
    Replies: 5
    Last Post: 15th November 2006, 08:41

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.