PDA

View Full Version : Displaying an image that is being generated in realtime



IrYoKu
21st August 2007, 13:59
Hi,

I am writing a simple scanline renderer, and would like to draw the image as it's generated, line by line.

I am using QGraphicsScene in order to display it. I am having two problems:

- QGraphicsScene only accepts QPixmaps, and I am unable to find a way of drawing pixels into them (apart from converting them into QImages).
- I cannot find a way of painting over a QPixmap that is part of a QGraphicsScene. There is a way of doing so?

Maybe there is other way of doing this, any comments are welcome.

Thanks in advance,
Jorge

marcel
21st August 2007, 16:28
I think you can do this with a QGraphicsView too.
Build a custom QGraphicsPixmapItem that holds an additional QImage and the current scanline. The QIMage needs to be initialized to the item size(in pixels)

Every time the renderer gives you a rendered buffer, compute the current scan line and set it in the QImage with QImage::scanLine. In the same time, update the item's pixmap from the QImage and also update the portion of the item that was invalidated by the new lines( by calling QGraphicsItem::update(const QRectF&)). You will get the desired rendering effect.

Another solution is to use a widget and a QImage as paint devices, but the implementation would be pretty much the same.

Regards

IrYoKu
21st August 2007, 21:05
In the same time, update the item's pixmap from the QImage


You mean update the QGraphicsPixmapItem internal pixmap with the QImage of my custom class? If yes, how can I access the internal pixmap? Or maybe I have to replace it completely using QGraphicsPixmapItem::setPixmap?

IrYoKu
25th August 2007, 16:53
Finally I managed to solve this problem by creating a derived class from QGraphicsItem and implementing boundingRect and paint. Very easy stuff.