Results 1 to 11 of 11

Thread: Optimize QGraphicsItem update

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2009
    Posts
    70

    Default Optimize QGraphicsItem update

    Hi, I want to show a video with QGraphicsView and QGraphicsItem.

    I need to show every 40 ms a QImage. I use a QTimeLine and a QGraphicsItem.

    The problem is that when I call the update() on the QTimeLine slot, there is a lot of time ( about 10 ms ) between the update() call and the paint event of the item.

    I know that there isn't an equivalent repaint() for the QGraphicsItem, but anyone know a way to reduce this time ??

    Thanks

  2. #2
    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: Optimize QGraphicsItem update

    The time depends on what your application is doing apart showing this one item. Without knowing any details it is not possible to suggest an optimization.
    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.


  3. #3
    Join Date
    Oct 2009
    Posts
    70

    Default Re: Optimize QGraphicsItem update

    The application is doing anything. I try to use QApplication:rocessEvents() after the update() call but it doesn't change nothing.

    Any ideas?
    Last edited by paolom; 21st March 2011 at 11:04.

  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: Optimize QGraphicsItem update

    Please show us some code (especially the part where you set the frames on the item). ProcessEvents will not help because the application will be processing events anyway. Also please state where you get the frames from.
    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
    Oct 2009
    Posts
    70

    Default Re: Optimize QGraphicsItem update

    This is the code:

    Qt Code:
    1. /* The QTimeLine slot called every 40 ms */
    2. void VideoItem::goToFrame(int frameNumber)
    3. {
    4. m_currentFrameNumber = frameNumber;
    5. updateFrame();
    6. }
    7.  
    8. void VideoItem::updateFrame()
    9. {
    10. if ( m_file )
    11. {
    12. QImage im;
    13. bool finished;
    14. if ( ( m_currentFrameNumber - m_previousFrameNumber ) == 1 )
    15. {
    16. im = m_file->getNextFrame(finished);
    17. }
    18. else
    19. {
    20. for ( int i = 0 ; i < ( m_currentFrameNumber - ( m_previousFrameNumber + 1 ) ) ; i++ )
    21. m_file->getNextFrame(finished,false);
    22.  
    23. if ( !finished )
    24. im = m_file->getNextFrame(finished);
    25.  
    26. }
    27.  
    28. m_previousFrameNumber = m_currentFrameNumber;
    29.  
    30. if ( !im.isNull() && !finished)
    31. {
    32. m_counter++;
    33. m_frameCount = m_currentFrameNumber;
    34.  
    35. setCurrentImage(im);
    36. }
    37. else
    38. {
    39.  
    40. stop();
    41.  
    42. emit videoFinished();
    43. }
    44. }
    45. }
    46.  
    47. void VideoItem::setCurrentImage(QImage im)
    48. {
    49. m_currentImage = im;
    50. update();
    51. }
    To copy to clipboard, switch view to plain text mode 

  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: Optimize QGraphicsItem update

    What is m_file and how does its getNextFrame work? Does it load an image from a file? Also, how large is each frame?
    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.


Similar Threads

  1. Update scene after moving QGraphicsItem
    By rogerholmes in forum Newbie
    Replies: 1
    Last Post: 19th January 2010, 05:08
  2. How to optimize qt libs for embedded x86?
    By yangyunzhao in forum Installation and Deployment
    Replies: 2
    Last Post: 30th June 2009, 09:47
  3. QGraphicsItem does not update
    By zgulser in forum Qt Programming
    Replies: 1
    Last Post: 5th February 2009, 14:44
  4. Optimize Qt Library
    By Svaths in forum Qt for Embedded and Mobile
    Replies: 11
    Last Post: 15th July 2007, 22:25
  5. Replies: 2
    Last Post: 26th April 2006, 10:43

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.