×

Discussion Board

Results 1 to 10 of 10

Threaded View

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    90

    Problem with QGraphicsView performance

    Hello,

    I have a QGraphicsScene (800X300, 96pp) and I'm having performance problems when I try to implement a background image in a QGraphisScene.

    There are not so many items, about ten. But it's really slow. Actually, it's going slower and slower. When the application is running about half minute it takes abut two seconds to react.

    My first approach was:

    Code:
    //scene_test is just 20KB
    QGraphicsPixmapItem* pPixScene = addPixmap(QPixmap(":/Scenes/Scene1/scene_test"));
        pPixScene->setPos(-78, -113);
        pPixScene = 0;
    Second approach:

    Code:
    QBrush brsh;
        brsh.setTexture(QPixmap(":/Scenes/Scene1/scene_test"));
        this->setBackgroundBrush(brsh);
    This is even worse, and if I try "m_pView->setCacheMode(QGraphicsView::CacheBackground);" it's definitly impossible.

    I think I've tried all the optimization possibilities... for instance:

    Code:
        m_pView->setContextMenuPolicy(Qt::NoContextMenu);
        m_pView->setDragMode(QGraphicsView::NoDrag);
        m_pView->setOptimizationFlags(QGraphicsView::DontSavePainterState |
                                      QGraphicsView::DontAdjustForAntialiasing);
        m_pView->setViewportUpdateMode(QGraphicsView::NoViewportUpdate/*QGraphicsView::SmartViewportUpdate*/);
    //The updates are called manually. As showed in the next piece of code
    
        m_pView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        m_pView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    I'm controlling the framerate with the next code. But it only fails when I add the background.

    Code:
    void CGameEngine::renderTimer()
    {
    	m_timer.start();
    
            renderElements();
    
    //Control the updates manually
            m_pCurrentScene->update();
    
            qDebug() << m_timer.elapsed();
            int iElapsed = 40-m_timer.elapsed(); //20 == 50 fps
            if(iElapsed > 0){
    		QTimer::singleShot(iElapsed, this, SLOT(renderTimer()));
                }
    	else
    	{
    		qDebug() << "Performance ERROR: " << iElapsed << " ms!!!!!!!";
    		renderTimer();	
    	}
    }
    what I don't understand is why this happens, it takes 2 or 3msec to execute all the code of each frame. Why can it be appearing so slow when I add the background?
    Any idea? thanks!
    Last edited by jano_alex_es; 2011-02-06 at 10:52. Reason: update information

Similar Threads

  1. QGraphicsView
    By vlad2048 in forum Qt
    Replies: 6
    Last Post: 2010-11-13, 23:19
  2. Urgent!!! Problem with Carbide Performance Investigator
    By amu09 in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2009-08-26, 09:20
  3. Replies: 4
    Last Post: 2007-11-26, 09:38
  4. Performance problem with Nokia Prototype SDK 4.0 emulators.
    By mikeaf in forum Mobile Java Tools & SDKs
    Replies: 7
    Last Post: 2006-08-04, 13:04

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×