Drawing performance [SOLVED]
I have a program that needs to draw many objects (7-8 QLists with lines and polygons, 1000 elements per list). But only one list is dynamic, that is, it needs to be redrawn every frame. The other need the redraw only on window resize or special mouse combination. How can I redraw only the list I want and the rest to be static until I need it?
Is QPixmap good for that and is there any sample for it?
Hi Xumepoc, have you tried with QGraphicsView widget? It can handle a lot of elements at a time, I'm not a 100% sure if it's good for dynamic elements too, but you can try it, setting a window with a QGraphicsView will only take you some minutes once you understand the class.
The concept it manages is about scenes. You must set a scene in order to add elements to it (lines, polygons,...) and then draw it. You can also navigate trough those elements to make changes to them.
I don't think QPixmap is a good class to draw lots of elements with individual attributes.
Thanks for he reply. I have been looking into QGraphicsView, but I think that is not what I am looking for. In MFC I could do the same thing by drawing the background to a CBitmap and just render the bitmap, unloading the CPU/GPU from the drawing stuff, and simply drawing the pixels. Is there a way I can do the same here and be that efficient.
the Qt Graphics framework is super-fast. At least as long as you do rendering with opengl which you can activate by passing -graphicssystem opengl to your application (or by calling the corresponding method od QApplication) in Qt4. In Qt5 I think it is active as a default and raster mode is used only as fallback. Can anyone confirm that?!? And it only repaints those areas in which a change occurred, so static content should usually not slow down you application.
Other then that painting can be done with "QPainter":http://qt-project.org/doc/qt-4.8/qpainter.html This will still be fast. However you will have to juggle around with different QPaintDevices (copy, modify, display etc.).
However it of course depends on what you want to do.
Well we are talking about a Geo Map, so when the user pan/zooms the background map has to be updated. So I can't just redraw the parts that has been changed, because that in fast is the entire background. I use QPainter for the drawing.
I did try to have a second "layer" as a child widget, and to redraw it on every 1 second, and the parent only when the user pans/zooms. But the problem there is that when the child widget is updated, the parent is also updated. Is there a way I can have the child updated (redrawn) only, but still display the parent content below?
I am not sure I make it clear :D
Still not exactly sure what you want the result to look like. Could you post a screenshot?!? However, I understood that much, that you have two types of content within the same drawing area, that need to be updated at differet point in time.
I would still advice you to try QGraphicsView Framework. I used it to make a zoomable map with more than a million items in it once, too. It worked smoothly on my 6 year old machine.
Anyhow, interfering in the update-cycles of Qt Widgets sounds as if might trigger a number of undesired side effects. If you want to stick with QPainter, I would do the drawing on different QImages. You could have one for your background and one for your changing content. When done, you could use "drawImage":http://qt-project.org/doc/qt-4.8/qpainter.html#drawImage-4 to draw the images one ontop of the other onto a widget.
However, it sounds that you are actually just reimplementing much of what the QGraphicsFramework does for you.
Hope it helps.
Well I will look into QGraphicsView. I managed to do it but using a QPixmap. When I need the background to be drawn, I draw it on a QPixmap and then display it. The upper layer gets redrawn every 100ms. So far I get around 399 FPS.
It is not only about QGraphicsView class. Qt provides several classes in kind of a small Framework. You can find a nice introduction to it "here":http://qt-project.org/doc/qt-4.8/graphicsview.html
Anyway, glad you got your solution.
The same here.
I would have done that with OpenGL since I’m better at that than I am with Qt classes, but if that works for you then it’s ok.
If solved, edit your post with the [Solved] label at the begining of the title.