PDA

View Full Version : QGraphicsView to fast update images



^NyAw^
8th May 2009, 11:38
Hi,

I'm trying to use a QGraphicsView to show a set of images that I have loaded into a QList<QImage*>.



for (int i=0; i<m_qImageList.count(); i++)
{
ui.graphicsView->setBackgroundBrush(QPixmap::fromImage(*m_qImageLis t.at(i)));
//ui.graphicsView->update(); //This makes nothing that I can see
//ui.graphicsView->repaint(); //This makes nothing that I can see
}
The problem is that I only can see the last image.

I want to force all the images to be painted. I don't know if using the background brush is the correct way to do this.

Thanks,

aamer4yu
8th May 2009, 12:17
The loop will set the last image as bacground image...
every time u use the setBackgroundBrush command, your previous brush will be overrided,,, isnt it ?

You will need to combine the images in list together into one image.

^NyAw^
8th May 2009, 12:29
Hi,

I didn't explained well.

I want the view to show image1, then image2, ... Imagine that the images are being grabbed from a web cam and I want to display them.
I know that I can use a QLabel, ... but I want to use Graphics View because I would like to insert some items on top of the image that have to be movable, resizable, ...

I have also tryied to add a pixmap item to the scene and update it from the images on the loop but I'm getting the same result.

Thanks,

wysota
8th May 2009, 13:27
Have a look at QGraphicsPixmapItem.

^NyAw^
8th May 2009, 13:39
Hi,


Have a look at QGraphicsPixmapItem (http://doc.trolltech.com/latest/qgraphicspixmapitem.html).

As I said:

I have also tryied to add a pixmap item to the scene and update it from the images on the loop but I'm getting the same result.I used a QGraphicsPixmapItem

Also I tryied to use a Thread that emits the Images and the main thread updates the pixmap on the PixmapItem.

Thanks,

wysota
8th May 2009, 14:02
I used a QGraphicsPixmapItem

Use more than one...

^NyAw^
8th May 2009, 15:55
Hi,

Why do I need more than one?

This gets me the same result.

wysota
8th May 2009, 16:31
Maybe I don't understand what you are trying to do... Are you trying to show all images at once or one at a time?

^NyAw^
8th May 2009, 16:46
Hi,



Imagine that the images are being grabbed from a web cam and I want to display them


So, what I want is to show every image that is captured. The camera is not a webcam and it can reach up to 70fps.
I want to try if it is possible to show th 70fps in real time.
I use the GraphicsView because I can add items on top of the showed image and because I can use OpenGL when the system is able to use it.

^NyAw^
8th May 2009, 18:25
Hi,

I have tryied to use a QThread that emits the image pointers and the main thread only paints them. Instead of using QImage I have used QPixmap.
If I force the thread to sleep 5 ms every loop iterarion I'm able to paint at 170fps. If I try to enable OpenGL it paints at 170fps but only some images are displayed.

Any idea?

Thanks,

wysota
8th May 2009, 18:50
What you are doing is asking for trouble but that's your choice. Anyway, your for() loop doesn't have a chance to show a sequence of images - you're iterating over all images at the same time so what you finally see is the last step of iteration. You don't need threads, all you need is to let Qt process events from time to time so that it has a chance to actually render something to the screen.

faldzip
8th May 2009, 22:17
You can use timer to fire each iteration:


// somewhere, lets say in constructor of SomeClass:
int m_i = 0; // class member
m_timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), SLOT(slotTimeout()));
m_timer->start(20);


// slotTimeout()
void SomeClass::slotTimeout()
{
// insert your image
++m_i; // generally ++i is faster than i++
}

That will give some time for event processing between timeouts.

Lykurg
8th May 2009, 23:17
I know that I can use a QLabel, ... but I want to use Graphics View
You can also use a QLabel inside the graphics view: QGraphicsScene::addWidget().