Results 1 to 13 of 13

Thread: QGraphicsView to fast update images

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QGraphicsView to fast update images

    Hi,

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

    Qt Code:
    1. for (int i=0; i<m_qImageList.count(); i++)
    2. {
    3. ui.graphicsView->setBackgroundBrush(QPixmap::fromImage(*m_qImageList.at(i)));
    4. //ui.graphicsView->update(); //This makes nothing that I can see
    5. //ui.graphicsView->repaint(); //This makes nothing that I can see
    6. }
    To copy to clipboard, switch view to plain text mode 
    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,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView to fast update images

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView to fast update images

    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,
    Òscar Llarch i Galán

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsView to fast update images

    Have a look at QGraphicsPixmapItem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView to fast update images

    Hi,

    Quote Originally Posted by wysota View Post
    Have a look at QGraphicsPixmapItem.
    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,
    Òscar Llarch i Galán

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsView to fast update images

    Quote Originally Posted by ^NyAw^ View Post
    I used a QGraphicsPixmapItem
    Use more than one...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView to fast update images

    Hi,

    Why do I need more than one?

    This gets me the same result.
    Òscar Llarch i Galán

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsView to fast update images

    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView to fast update images

    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.
    Last edited by ^NyAw^; 8th May 2009 at 15:52.
    Òscar Llarch i Galán

  10. #10
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView to fast update images

    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,
    Òscar Llarch i Galán

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsView to fast update images

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView to fast update images

    You can use timer to fire each iteration:
    Qt Code:
    1. // somewhere, lets say in constructor of SomeClass:
    2. int m_i = 0; // class member
    3. m_timer = new QTimer(this);
    4. connect(timer, SIGNAL(timeout()), SLOT(slotTimeout()));
    5. m_timer->start(20);
    6.  
    7.  
    8. // slotTimeout()
    9. void SomeClass::slotTimeout()
    10. {
    11. // insert your image
    12. ++m_i; // generally ++i is faster than i++
    13. }
    To copy to clipboard, switch view to plain text mode 
    That will give some time for event processing between timeouts.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  13. #13
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QGraphicsView to fast update images

    Quote Originally Posted by ^NyAw^ View Post
    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().

Similar Threads

  1. QGraphicsView won't update until resize
    By stevel in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2009, 21:45
  2. QGraphicsView and fast moving objects
    By deMarco in forum Qt Programming
    Replies: 4
    Last Post: 26th February 2009, 11:07
  3. Qt Draw fast png images
    By anafor2004 in forum Newbie
    Replies: 4
    Last Post: 4th November 2008, 09:28
  4. Problem with QGraphicsView and ItemIgnoresTransformations
    By coderCPP1981 in forum Qt Programming
    Replies: 6
    Last Post: 27th June 2008, 05:28
  5. QGraphicsView user-resizable images - for children
    By magland in forum Qt Programming
    Replies: 2
    Last Post: 5th October 2007, 16:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.