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:
//scene_test is just 20KB
pPixScene->setPos(-78, -113);
pPixScene = 0;
//scene_test is just 20KB
QGraphicsPixmapItem* pPixScene = addPixmap(QPixmap(":/Scenes/Scene1/scene_test"));
pPixScene->setPos(-78, -113);
pPixScene = 0;
To copy to clipboard, switch view to plain text mode
Second approach:
brsh.
setTexture(QPixmap(":/Scenes/Scene1/scene_test"));
this->setBackgroundBrush(brsh);
QBrush brsh;
brsh.setTexture(QPixmap(":/Scenes/Scene1/scene_test"));
this->setBackgroundBrush(brsh);
To copy to clipboard, switch view to plain text mode
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:
m_pView->setContextMenuPolicy(Qt::NoContextMenu);
m_pView
->setOptimizationFlags
(QGraphicsView::DontSavePainterState |
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);
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);
To copy to clipboard, switch view to plain text mode
I'm controlling the framerate with the next code. But it only fails when I add the background.
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();
}
}
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();
}
}
To copy to clipboard, switch view to plain text mode
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!
Bookmarks