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
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    29

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

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

    Quote Originally Posted by christina123y View Post
    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,
    This is the nature of your graph. You can modify the graph item to be composed of many smaller items each forming a cluster of points and you will immediately gain a speedup as only those clusters that are visible will be drawn.

    my item's boundingrect change as zoom in proportion,
    I don't think you should change your item's bounding rect when you zoom. It's not zooming anymore if you do and Graphics View won't be able to help you much with it.

    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
    Yes, that's why you have to increase the cache size. The item can't be redrawn out of thin air - either its verbatim copy has to be stored somewhere (like in the cache) and that uses up memory or it has to be redrawn everytime from scratch. There is no third way.

    and when the mouse move on the item, the graph is repaint too slowly ,event i can't drag the scrollbar on the graphicsview.
    Again, splitting your item into smaller pieces will give you significant speedup. You can also disable interactivity of the view by calling QGraphicsView::setInteractive(false) which should prevent your items from being repainted as a reaction to mouse events.

    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 ).
    I don't know how would you expect it to work then There is no "infinity" in computer language. The amount of memory is limited and once you go over the edge your application will start acting abnormally.

    Third, i didn't catch what you say to set the viewport of the view to QGLWidget clealy.
    Qt Code:
    1. myView->setViewport(new QGLWidget);
    To copy to clipboard, switch view to plain text mode 

    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.
    Split the item. You can control the extent of splitting by setting a minimum/maximum number of points per cluster. If you have a single item that is larger than the area of the viewport you can see in the view then the item has to be redrawn completely anyway - including all the points in the graph. Now if you split the graph into many items, only those clusters of points that are visible will have to be redrawn. This is a speedup you get practically for free, without any caching or anything. It's worth a shot.
    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 (11th April 2009)

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

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

    Quote Originally Posted by wysota View Post
    This is the nature of your graph. You can modify the graph item to be composed of many smaller items each forming a cluster of points and you will immediately gain a speedup as only those clusters that are visible will be drawn.

    Again, splitting your item into smaller pieces will give you significant speedup. You can also disable interactivity of the view by calling QGraphicsView::setInteractive(false) which should prevent your items from being repainted as a reaction to mouse events.

    Split the item. You can control the extent of splitting by setting a minimum/maximum number of points per cluster. If you have a single item that is larger than the area of the viewport you can see in the view then the item has to be redrawn completely anyway - including all the points in the graph. Now if you split the graph into many items, only those clusters of points that are visible will have to be redrawn. This is a speedup you get practically for free, without any caching or anything. It's worth a shot.

    hi, extremely grateful for your so good suggestion. Originally, my design to draw all points in an item in view of it will be easy to operate. and if i splitter all the points to several items, i don't know how to put these items together!
    now,according to your direction, my thought is : splitter QVector<QPointF> vector which stores all the points to several segment, and then draw each segment's points on an item, but how can i put these items together appropriately just to compose integrate and correct graph, this means how i know where to put these small items, and how can i map each segment points to corresponding item's coordinate.
    And here is another question ,because when my application first start ,the whole graph is shown, and i splitter it to several items , when i zoom in , the graph is scaled, and how can i determin which items should be repainted(even i don't know after zooming in, which of these small items will be in the visible area), and if some points of a small item are in the visible area, other are not, then repaint? and if i zoom in the graph ,the items which are in the visible area , whether their boundingrect change as the zoom in proportions, or just use the QGraphicsItem::scale() to achieve this.
    wish i has expressed clearly .
    and looking forward to your reply again.
    best appreciated to you.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

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

    Quote Originally Posted by christina123y View Post
    Originally, my design to draw all points in an item in view of it will be easy to operate. and if i splitter all the points to several items, i don't know how to put these items together!
    I'm not sure what you mean by putting them together. You can have an item that represents the background of the graph (axis, etc.) and have multiple items that are child items of the graph item representing the contents of the graph (points).

    now,according to your direction, my thought is : splitter QVector<QPointF> vector which stores all the points to several segment, and then draw each segment's points on an item, but how can i put these items together appropriately just to compose integrate and correct graph, this means how i know where to put these small items, and how can i map each segment points to corresponding item's coordinate.
    For splitting space usually an algorithm called BSP (binary space partitioning) is used. It splits the plane into two sub-planes and then splits each sub-plane again and again until it reaches the stop condition. GraphicsView uses that algorithm internally to quickly find items based on their geometry. If you decided to represent each point in the graph as separate item, you could automatically use that built-in mechanism but if you want to have clusters, you have to implement BSP yourself.

    and how can i determin which items should be repainted
    Qt does that for you. It will only repaint items that need repainting (i.e. those that are visible and have been marked as dirty).


    A rule of a thumb is that if you have one item in the scene - you probably shouldn't be using QGraphicsView at all as it only adds to the complexity giving nothing in exchange. If you want to use Graphics View, have multiple items. Group them as you want using the parent-child relationship and squeeze as much from the architecture as possible.

    If you only want a single item with zooming and scrolling, you'll get much better results with a custom widget derived from QAbstractScrollArea.
    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.


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

    christina123y (12th April 2009)

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

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

    Quote Originally Posted by wysota View Post
    I'm not sure what you mean by putting them together. You can have an item that represents the background of the graph (axis, etc.) and have multiple items that are child items of the graph item representing the contents of the graph (points).
    today i have tried that each point as a child qgraphicsitem, and set a coordinate item as their parent, and it did draw correct graph. but, my points is larger then 12,0000
    (they are float type ) ,i found ithat when i zoom in the graph to some extents it become slowly again,fairly slowly ,even make my application dead.

    Quote Originally Posted by wysota View Post
    For splitting space usually an algorithm called BSP (binary space partitioning) is used. It splits the plane into two sub-planes and then splits each sub-plane again and again until it reaches the stop condition. GraphicsView uses that algorithm internally to quickly find items based on their geometry.
    i have look up the reference of BSP , but it is still obscure to me.maybe i should spend some time to investigate this. would you please provide me some relative reference? thank you.

    Quote Originally Posted by wysota View Post
    If you decided to represent each point in the graph as separate item, you could automatically use that built-in mechanism but if you want to have clusters, you have to implement BSP yourself.
    what do you mean "automatically use that built-in mechanism "? i make each point as a separate item, and then use QGraphicsItem::setPos() in its parent item. how should i use
    alleged built-in mechanism ? Or Qt does that itself? but why didn't this way improve the speed. and it still repaint very slowly.

    Quote Originally Posted by wysota View Post
    A rule of a thumb is that if you have one item in the scene - you probably shouldn't be using QGraphicsView at all as it only adds to the complexity giving nothing in exchange. If you want to use Graphics View, have multiple items. Group them as you want using the parent-child relationship and squeeze as much from the architecture as possible.
    If you only want a single item with zooming and scrolling, you'll get much better results with a custom widget derived from QAbstractScrollArea.
    i use QGraphicsView for i need to make my application perform other functions such as mouse tracker, and so on. next time i will think over what frame or just qwidget to use.and with great thanks to your advice.and how to use BSP to achieve improving speed of repaint?

    best wishes to you!

  8. #6
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    4
    Thanked 140 Times in 132 Posts

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

    I think you might take a closer look into "40000 chips" demo from Qt, but I'm not sure that it's what you want: http://doc.trolltech.com/4.5/demos-chip.html
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  9. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

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

    Quote Originally Posted by christina123y View Post
    today i have tried that each point as a child qgraphicsitem, and set a coordinate item as their parent, and it did draw correct graph. but, my points is larger then 12,0000
    (they are float type ) ,i found ithat when i zoom in the graph to some extents it become slowly again,fairly slowly ,even make my application dead.
    Zooming in should make your application faster not slower. You must have done something wrong.

    i have look up the reference of BSP , but it is still obscure to me.maybe i should spend some time to investigate this. would you please provide me some relative reference? thank you.
    It's a very popular algorithm. It's 3D version (based on octree) is used in most 3D FPP/TPP games to speed up rendering by cutting out objects that are not in the viewing frustum. I'm sure you'll find lots of materials on the subject.

    what do you mean "automatically use that built-in mechanism "? i make each point as a separate item, and then use QGraphicsItem::setPos() in its parent item. how should i use
    alleged built-in mechanism ? Or Qt does that itself?
    If each point is a separate item then you already use this mechanism.

    but why didn't this way improve the speed. and it still repaint very slowly.
    I'd have to see the code. You can search the forum. Some time ago as a reply to one of Ini's complaints about QGraphicsView functionality I made a proof of concept and posted it here. As far as I remember the application contained 10k points in a form of zoomable graph. You can see an example implementation there.

    i use QGraphicsView for i need to make my application perform other functions such as mouse tracker, and so on.
    You can do the same with a regular widget. There is only one usecase currently where you'd want to use graphics view when having a single item and that's not your usecase.

    and how to use BSP to achieve improving speed of repaint?
    Group your points into clusters. This requires a bit of more computation power when preparing the graph but once it's there you should get a significant speedup. You can use the "K nearest neighbours" and/or "K-Means" algorithms for clustering. The first algorithm is a classification algorithm which can prove useful once you "teach" your graph the characteristics of your data. It will make it possible to quickly find the appropriate cluster for a new point. The second algorithm is a classical clustering algorithm.
    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 (17th April 2009)

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

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

    First ,thank you very much, these days, i have tried another way to improve the speed of repainting, but it still didn't resovle essential problem. now allow me to depict my method: I still draw all the points in a pixmap ,then draw pixmap to a single item, and draw coordinate system as the same way. when i zoom in the graph, i newly adjust the item's boundingRect with the corresponding proportion. and draw the whole points in the item.only when the item's width and height
    overrun the range (the range within the cache mode--ItemCordinateCache can support), then repaint the graph, however,while the mouse move what i need to do is that to draw pixmap on the item. this really has improve the speed of repaint while mouse move.
    wish i has explain my thought clearly.
    but when zoom in the graph ,the first time to repaint the graph is still slow, and feels very very slowly when you move the scrollbar to see graph in the invisible area.
    maybe i should look up other way for solution.

    Quote Originally Posted by wysota View Post
    Zooming in should make your application faster not slower. You must have done something wrong..
    i have checked out ,i really draw each point as a single item. but it really feels very slowly.


    Quote Originally Posted by wysota View Post
    It's a very popular algorithm. It's 3D version (based on octree) is used in most 3D FPP/TPP games to speed up rendering by cutting out objects that are not in the viewing frustum. I'm sure you'll find lots of materials on the subject.
    hn,i have looked up some reference on it, and i found it very hard, and i still didn't know to to apply to my application. these days , i have given up on this solution, but my solution still didn't works well, maybe i should penetrate into this method.


    Quote Originally Posted by wysota View Post
    I'd have to see the code. You can search the forum. Some time ago as a reply to one of Ini's complaints about QGraphicsView functionality I made a proof of concept and posted it here. As far as I remember the application contained 10k points in a form of zoomable graph. You can see an example implementation there.
    Could you please show me the URL where you post it and the example , i haven't found it , thank you.

    best wishes to you. and looking forward to your reply.

  12. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

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

    Quote Originally Posted by christina123y View Post
    however,while the mouse move what i need to do is that to draw pixmap on the item. this really has improve the speed of repaint while mouse move.
    That's the first solution I described. And caching works exactly the same way only that it does the bookkeeping itself without you having to care.

    but when zoom in the graph ,the first time to repaint the graph is still slow,
    and feels very very slowly when you move the scrollbar to see graph in the invisible area.
    maybe i should look up other way for solution.
    This is because you have a single item - the whole pixmap has to be regenerated and rendered onto the viewport although only a part of it is visible.

    i have checked out ,i really draw each point as a single item. but it really feels very slowly.
    Zooming should reduce the number of paint operations. If it doesn't (or if it increases it) then there is something wrong with your code.

    hn,i have looked up some reference on it, and i found it very hard, and i still didn't know to to apply to my application. these days , i have given up on this solution, but my solution still didn't works well, maybe i should penetrate into this method.
    It's not that hard, the algorithm is very simple. The only thing is that you have to know why you are doing things you are doing and not just because some fool on QtCentre forum told you to do it

    Could you please show me the URL where you post it and the example , i haven't found it , thank you.
    It's here somewhere. Use the search facilities of the forum to search through threads started by the user I mentioned before.
    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. 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
  •  
Qt is a trademark of The Qt Company.