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:
Second approach:Code://scene_test is just 20KB QGraphicsPixmapItem* pPixScene = addPixmap(QPixmap(":/Scenes/Scene1/scene_test")); pPixScene->setPos(-78, -113); pPixScene = 0;
This is even worse, and if I try "m_pView->setCacheMode(QGraphicsView::CacheBackground);" it's definitly impossible.Code:QBrush brsh; brsh.setTexture(QPixmap(":/Scenes/Scene1/scene_test")); this->setBackgroundBrush(brsh);
I think I've tried all the optimization possibilities... for instance:
I'm controlling the framerate with the next code. But it only fails when I add the background.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);
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?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(); } }
Any idea? thanks!

rocessEvents().


