PDA

View Full Version : Graphics View : too many lines



natnan
27th January 2010, 14:17
Hi,

In my project I need to put lots of lines into the graphics scene. Thousands of graphicsscene::addLine decrease the program's performance dramatically as you can guess.
I don't know why but polyline doesn't exist for graphics scene and I need graphics view architecture since the project will be an interactive one.

Any ideas?

Thanks.

jano_alex_es
27th January 2010, 15:21
Do you need to interact with them? if not, you can draw them in the paint event instead of creating QGraphicsLineItem.

faldzip
27th January 2010, 15:38
I don't know why but polyline doesn't exist for graphics scene
Take a look at the QGraphicsPathItem and QGraphicsPolygonItem.

natnan
27th January 2010, 16:05
@jano_alex_es
Yes, I need to interact with them.


I'm already using qpolygonItem in my project as well. Polygons merge the first point and the last point, something I don't want.
I'm guessing path does the same as far as I've read.

dchow
28th January 2010, 01:38
Just curious, when you say 'thousands', do you mean 1000, 10000, 100000? For the project I'm working on, I've actually been able to display somewhere around 10,000 QGraphicsItems at a time with minimal slowdown (although, for some reason with 4.6.1 there's a big performance hit; works fine in 4.5.2). At worst case, there is actually have upwards of about 100,000 QGraphicsItems in the QGraphicsScene (not all being displayed) at any one time. When the scene reaches such high numbers then I do start seeing significant slow down.

To manage the performance, I try to make sure only that only the items that actually need to be displayed are shown and I try to limit the instantiation of the QGraphicsItems to be only as needed.

Also, take a look at the 40,000 Chips demo that comes with the Qt install. For the most part, this demo works fine and there are 40,000 graphical items on the screen at worst case. So, if you have a few thousand lines you shouldn't have any problems with performance.

Good Luck!

natnan
28th January 2010, 09:25
It's actually 56740 lines :P. But there will be much more.. There are lots of polygons, texts and images in the screen as well (not 56k of course).
The problem is probably not the lines but creating 56k graphicsItem. Unnecessary memory consumption too.
Before noticing graphics view I started this project with QPainter, and I printed the same amount of lines with polyline, it was no problem at all.

JohannesMunk
28th January 2010, 12:15
Can't you group those lines into bigger objects? And draw these objects using polyline, except when the user is editing an object? You would need to create the required QGraphicsLineItem's when beginning to edit and removing them when finished.