I forgot to mention the 3rd point, which doesn't have a code example but is just a suggestion... If you can manage to draw these nodes purely with QPainter, that would make it very fast. You might be able to still use an svg for the small icon or even a higher res pixmap. But the node itself is pretty simple and could be designed with QPainter.
On Apr 4, 2013, at 10:36 PM, Justin Israel wrote: > I was kind of hoping you had a small, concise example, since it took a while > to go through all of that code and figure out where possible slow downs could > be coming from. But I went through and turned off as much as possible to > narrow it down to simply the QGraphicsSvgItem subclass.. > > Here are two things you can play with to improve performance: > http://pastebin.com/7Pip1BuL > > 1. Using a shared renderer for the same svg. It was already a big improvement > when I switched it to not load new svg items every time for every item. > Unfortunately svg items are really slow to render when you have them all in a > group near each other. So if they can all just come from one render source, > the speed increases. > > 2. Caching a pixmap manually during a drag operation. I flag the mouse press > event, and then create a cached pixmap of the item in the move event. Then > when the paint event occurs, it sees the cached pixmap and paints that > instead of asking the svg renderer to do anything. When the mouse is > released, the flag is unset and it goes back to painting from svg again. > I didn't have much time to spend on this so I was a bit hackish in > determining a resolution. Just picked a multiplier for the size. Ideally it > would be matched to the views scale a bit better so that you can render a > really small pixmap when its zoomed out and then a high res only when its > really zoomed in. > > Hope that helps. Mainly...the svgs are slow :-/ > Maybe there are other tweaks to be made somewhere, but I would have to spend > more time. > > > -- justin > > > On Apr 4, 2013, at 1:39 AM, Tuan Nguyen wrote: > >> Here's my work that i had posted earlier . It's contain script for the GUI, >> ai file, icons...... You can find the setup for QGraphicsView and >> QGraphicsScene in GraphicsModule.py . Setting for QGraphicsItem inside >> NodeModule and skip all the rest :3 >> >> and use this to call it up >> >> from Lib import GraphicsModule >> GraphicsModule.showUi() >> >> http://www.mediafire.com/download.php?l8giq5l992jj2bh >> >> Group doesn't allow attach large file, so i upload it to some host :( >> >> Thank Justin :3 >> >> >> On Wed, Apr 3, 2013 at 7:24 PM, Tuan Nguyen <[email protected]> wrote: >> Here's my work that i had posted earlier . It's contain script for the GUI, >> ai file, icons...... You can find the setup for QGraphicsView and >> QGraphicsScene in GraphicsModule.py . Setting for QGraphicsItem inside >> NodeModule and skip all the rest :3 >> >> and use this to call it up >> >> from Lib import GraphicsModule >> GraphicsModule.showUi() >> >> Thank Justin :3 >> >> >> On Wed, Apr 3, 2013 at 5:39 PM, Justin Israel <[email protected]> wrote: >> I was asking if you could zip up a short working example demonstrating the >> slowness, so that I could download it, test it out, and report back about >> why it might be running slowly. >> >> >> On Apr 3, 2013, at 8:45 PM, Tuan Nguyen wrote: >> >>> Yes, please :3 >>> >>> >>> On Wed, Apr 3, 2013 at 2:30 PM, Justin Israel <[email protected]> >>> wrote: >>> There are optimizations for the QGraphicsView, but I wouldn't think you >>> would need them right away with just a few items. Also the default >>> ViewportUpdateMode should be the MinimalViewportUpdate which tries and >>> draws only the smallest partial areas of the scene that change. Moving one >>> item should only be drawing small portions at a time. >>> You would probably want to make sure you have the default >>> DeviceCoordinateCache set for the CacheMode of the items. >>> >>> If you want to zip up a working minimal example that exhibits the slowness, >>> I will take a look at it for you. >>> >>> >>> >>> On Apr 3, 2013, at 7:51 PM, Tuan Nguyen wrote: >>> >>>> Sorry, i had fixed the the indents. And yes, it slows when i try to moving >>>> them (the UI) around. not when i create them. This problem not relate to >>>> how we setup the GraphicsView and Scene, isn't it? >>>> >>>> I will try what you told me first :3 >>>> >>>> >>>> On Wed, Apr 3, 2013 at 1:06 PM, Justin Israel <[email protected]> >>>> wrote: >>>> The formatting and indents are all messed up on that gist. But it doesn't >>>> look like you are doing much of anything in the paint event. Is it slow to >>>> add them to the scene, or slow when you have 1000 of them and are just >>>> moving them around? >>>> >>>> One thing I can see is that it may be related to the sheer number of >>>> individual svg images being loaded. What you might want to do is share a >>>> renderer for svgs that you constantly load. For instance, you have the >>>> common ":/Scene_ConnectNode.svg" image being loaded multiple times for >>>> every GSceneItem; once for the output and then N number of input keyItems. >>>> What you could do is create just one renderer for it and store it on the >>>> scene or whereever, and then set that renderer on every new Connectionitem: >>>> >>>> ## >>>> self._connRenderer = QSvgRenderer(':/Scene_ConnectNode.svg') >>>> ... >>>> inputNode = ConnectionItem(self) >>>> inputNode.setSharedRenderer(self._connRenderer) >>>> self.inputNode[key] = inputNode >>>> ... >>>> outputNode = ConnectionItem(self) >>>> outputNode.setSharedRenderer(self._connRenderer) >>>> self.outputNode = outputNode >>>> ## >>>> >>>> You could also do the same for your node.sceneImage paths if they are a >>>> common set. Keep a dictionary of renderers mapping to the path, and set >>>> the shared renderer on each one. This might greatly reduce the number of >>>> times you are loading this into memory. Though for all I know, Qt might be >>>> doing some smart caching under the hood. But if its anything similar to >>>> QPixmaps, this would work. I do the same with QPixmapCache, to cache the >>>> same path instead of loading a new one for each. >>>> >>>> Also the docs say that by default caching is enabled so you shouldnt have >>>> to mess with any of that to get performance. >>>> >>>> >>>> >>>> >>>> On Wed, Apr 3, 2013 at 6:33 PM, Tuan Nguyen <[email protected]> wrote: >>>> The first thing i had found out is the svg image i use for GraphicsItem is >>>> too complicate, after i remove all the detail from it, it runs a little >>>> smoothly but thousands of items O.O, i can't even imagine it. Here is the >>>> class of GraphicsItem i used >>>> >>>> https://gist.github.com/illunara/5298674 >>>> >>>> Thanks for reply >>>> >>>> >>>> On Wed, Apr 3, 2013 at 6:04 AM, Judah Baron <[email protected]> wrote: >>>> Yeah, that sounds suspicious. What's going on with those 20 items? >>>> >>>> >>>> On Tue, Apr 2, 2013 at 11:07 AM, Justin Israel <[email protected]> >>>> wrote: >>>> 20 items is by no means "a lot". I have had scenes with thousands of >>>> items. It sounds like you might be doing something heavy in your paint >>>> events. >>>> Can you provide some more details about the items you are using? Snippet? >>>> On Apr 3, 2013 1:01 AM, "illunara" <[email protected]> wrote: >>>> Hi everybody >>>> I'm working with QGraphicsView for a while, and after had finished some >>>> basic stuff, i realized it gets slow down when there are a lot of items >>>> (around 20, and it will freeze). >>>> >>>> When i set cacheMode in QGraphicsItem to ItemCoordinateCache which will >>>> block the paintEvent, the performance is improve. So i guess that is the >>>> cause. However, i don't know how to solve this yet :( >>>> >>>> Thanks >>>> >>>> -- >>>> You received this message because you are subscribed to the Google Groups >>>> "Python Programming for Autodesk Maya" group. >>>> To unsubscribe from this group and stop receiving emails from it, send an >>>> email to [email protected]. >>>> To post to this group, send email to [email protected]. >>>> For more options, visit https://groups.google.com/groups/opt_out. >>>> >>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google Groups >>>> "Python Programming for Autodesk Maya" group. >>>> To unsubscribe from this group and stop receiving emails from it, send an >>>> email to [email protected]. >>>> To post to this group, send email to [email protected]. >>>> For more options, visit https://groups.google.com/groups/opt_out. >>>> >>>> >>>> >>>> >>>> -- >>>> You received this message because you are subscribed to a topic in the >>>> Google Groups "Python Programming for Autodesk Maya" group. >>>> To unsubscribe from this topic, visit >>>> https://groups.google.com/d/topic/python_inside_maya/KO-lFG2GYMY/unsubscribe?hl=en-US. >>>> To unsubscribe from this group and all its topics, send an email to >>>> [email protected]. >>>> >>>> To post to this group, send email to [email protected]. >>>> For more options, visit https://groups.google.com/groups/opt_out. >>>> >>>> >>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google Groups >>>> "Python Programming for Autodesk Maya" group. >>>> To unsubscribe from this group and stop receiving emails from it, send an >>>> email to [email protected]. >>>> To post to this group, send email to [email protected]. >>>> For more options, visit https://groups.google.com/groups/opt_out. >>>> >>>> >>>> >>>> >>>> -- >>>> You received this message because you are subscribed to a topic in the >>>> Google Groups "Python Programming for Autodesk Maya" group. >>>> To unsubscribe from this topic, visit >>>> https://groups.google.com/d/topic/python_inside_maya/KO-lFG2GYMY/unsubscribe?hl=en-US. >>>> To unsubscribe from this group and all its topics, send an email to >>>> [email protected]. >>>> To post to this group, send email to [email protected]. >>>> For more options, visit https://groups.google.com/groups/opt_out. >>>> >>>> >>>> >>>> >>>> -- >>>> You received this message because you are subscribed to the Google Groups >>>> "Python Programming for Autodesk Maya" group. >>>> To unsubscribe from this group and stop receiving emails from it, send an >>>> email to [email protected]. >>>> To post to this group, send email to [email protected]. >>>> For more options, visit https://groups.google.com/groups/opt_out. >>>> >>>> >>> >>> >>> -- >>> You received this message because you are subscribed to a topic in the >>> Google Groups "Python Programming for Autodesk Maya" group. >>> To unsubscribe from this topic, visit >>> https://groups.google.com/d/topic/python_inside_maya/KO-lFG2GYMY/unsubscribe?hl=en-US. >>> To unsubscribe from this group and all its topics, send an email to >>> [email protected]. >>> To post to this group, send email to [email protected]. >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >>> >>> >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Python Programming for Autodesk Maya" group. >>> To unsubscribe from this group and stop receiving emails from it, send an >>> email to [email protected]. >>> To post to this group, send email to [email protected]. >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >>> >> >> >> -- >> You received this message because you are subscribed to a topic in the >> Google Groups "Python Programming for Autodesk Maya" group. >> To unsubscribe from this topic, visit >> https://groups.google.com/d/topic/python_inside_maya/KO-lFG2GYMY/unsubscribe?hl=en-US. >> To unsubscribe from this group and all its topics, send an email to >> [email protected]. >> To post to this group, send email to [email protected]. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> >> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Python Programming for Autodesk Maya" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To post to this group, send email to [email protected]. >> For more options, visit https://groups.google.com/groups/opt_out. >> >> > -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
