QGraphicsScene with custom QPainter
-
@mrjj Thank you for your reply!
Our rendering algorithms are optimized to use whatever hardware acceleration is available on the target system. If we want to draw a rectangle and the target hardware provides hardware acceleration for rectangle drawing we will use that. It's very similar to how
QPainter
/QPaintEngine
works. After all the library was inspired by Qt ;)
Anyway, all our rendering algorithms have a fallback to basicdrawPixel()
. This means that the only interface we need to Qt is the ability to manually draw pixels. If we can use hardware acceleration routines for rendering rectangles and so on we will be happily using them, but if that's not (easily) possible, we can work withdrawPixel()
only without any problem. -
Ok. Im asking
as in a GUI Designer, often the needed refresh rate is not very high so
I wondering if you could hook up your algorithms with
http://doc.qt.io/qt-5.5/qimage.html#scanLine
and that way provide exact preview of what he will get. -
If I understand you correctly I would maintain my own framebuffer to which I render using my algorithms (which is very easy for me) and then create a QImage that spans the entire display area (the entire scene) and copy the framebuffer to the QImage?
You linked to theQImage::scanLine()
method but I don't know how that helps in my case. If anything I would need to provide ascanLine()
function to my own framebuffer which theQGraphiscScene
can use, no?Another issue I have is that I still need to use QGraphicsItems as I need to be able to move the items in the QGraphisScene, and use other features like that.
Maybe it would be possible that I maintain one framebuffer per QGraphicsItem myself and then dump that framebuffer to the scene in theQGraphicsScene
in myQGraphicsItem::paint()
function? -
Oh, that sounds more advanced that I was thinking :)
I was thinking pr Designer Item/widget.
So we have a custom QGraphicsItem that will paint a image.
This image is painted by your algorithms
and the QGraphicsItem just show it in scene.Oh.
"Maybe it would be possible that I maintain one framebuffer per QGraphicsItem "
yes. That was my idea. Maybe its stupid but would be easy to test. -
For me both is possible: I can either have a global framebuffer that contains the entire scene or I can have one buffer per
QGraphicsItem
. Our existing software design allows using either without modifying our renderers. So whatever is easier in terms of Qt will work.I would prefer to maintain one custom buffer per
QGraphicsItem
and then just dump that on the scene using aQPixmap
or aQImage
. -
Well I sort of like the one buffer pr item better - also -
as it seems more flexible than render whole scene. :) -
Is it correct that I should prefer using a
QPixmap
instead of aQImage
for this purpose? -
Well depends on what you need pixels wise.
QImage has better support for
image manipulation and QPixmap is optimized for fast drawing.So you might need QImage to generate the buffer but later convert to pixmap for
repeated drawing.Its a wide question as seen here
http://stackoverflow.com/questions/10307860/what-is-the-difference-between-qimage-and-qpixmap:)
-
Thank you very much for your help, I appreciate it a lot!
I'll try to get this done in the next couple of days. -
@Joel-Bodenmann
You are very welcome.
I hope it will work as fine as I imagine :)Good luck and happy coding !