kalos80
12th January 2010, 13:24
Hi,
I have an application showing thousand of items (lines, points, polygons).
the user can click a button to show/hide all those items.
I'm porting that application from Qt3 to Qt4 (4.5.1).
The application was working greatily in Qt3, but after porting it to Qt4 I'm noticing it is extremely slower showing and hiding items. Debugging it deeply I found out that the bottleneck is the showing of points (QGraphicsEllipseItems) that is causing the application to get stuck. Actually to show 10000 points (QGraphicsEllipseItems w = 4 and h = 4) it took more that 5 minutes while in Qt3 it was almost instantaneous.
The same amount of Lines and Polygons is shown quite fast (just a few seconds).
I disabled the indexing in QGraphicsScene just to avoid it was causing the slowness, but it seems it didn't cause any improvement.
Am I missing something?
Here is part of the code I'm using to create and show the items. Attache is the whole Qt project.
MainWindow::MainWindow( QWidget * parent, Qt::WindowFlags flags)
: QMainWindow(parent, flags)
{
...
scene = new QGraphicsScene(this);
scene->setSceneRect(0, 0, 800, 600);
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
scene->setBackgroundBrush(Qt::black);
gvView->setScene(scene);
// create the items
createNPoints(10000);
}
/*
* create some points
*/
void MainWindow::createNPoints(int num)
{
for( int i = 0; i < num; i++ )
createPoint();
}
void MainWindow::createPoint()
{
QGraphicsEllipseItem *p = scene->addEllipse(qrand()%int(scene->width()),qrand()%int(scene->height()), 4, 4);
QColor c(qrand()%32*8,qrand()%32*8,qrand()%32*8);
p->setPen(c);
p->setBrush(c);
p->setZValue(qrand()%256);
pointsList.append(p);
}
/*
This is the slot called when the user clicks the button to show the items
*/
void MainWindow::showPoints(bool yes)
{
for(int i = 0; i < pointsList.count(); i++)
{
if(yes)
pointsList[i]->show();
else
pointsList[i]->hide();
}
}
Thanks in advance for your help.
I have an application showing thousand of items (lines, points, polygons).
the user can click a button to show/hide all those items.
I'm porting that application from Qt3 to Qt4 (4.5.1).
The application was working greatily in Qt3, but after porting it to Qt4 I'm noticing it is extremely slower showing and hiding items. Debugging it deeply I found out that the bottleneck is the showing of points (QGraphicsEllipseItems) that is causing the application to get stuck. Actually to show 10000 points (QGraphicsEllipseItems w = 4 and h = 4) it took more that 5 minutes while in Qt3 it was almost instantaneous.
The same amount of Lines and Polygons is shown quite fast (just a few seconds).
I disabled the indexing in QGraphicsScene just to avoid it was causing the slowness, but it seems it didn't cause any improvement.
Am I missing something?
Here is part of the code I'm using to create and show the items. Attache is the whole Qt project.
MainWindow::MainWindow( QWidget * parent, Qt::WindowFlags flags)
: QMainWindow(parent, flags)
{
...
scene = new QGraphicsScene(this);
scene->setSceneRect(0, 0, 800, 600);
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
scene->setBackgroundBrush(Qt::black);
gvView->setScene(scene);
// create the items
createNPoints(10000);
}
/*
* create some points
*/
void MainWindow::createNPoints(int num)
{
for( int i = 0; i < num; i++ )
createPoint();
}
void MainWindow::createPoint()
{
QGraphicsEllipseItem *p = scene->addEllipse(qrand()%int(scene->width()),qrand()%int(scene->height()), 4, 4);
QColor c(qrand()%32*8,qrand()%32*8,qrand()%32*8);
p->setPen(c);
p->setBrush(c);
p->setZValue(qrand()%256);
pointsList.append(p);
}
/*
This is the slot called when the user clicks the button to show the items
*/
void MainWindow::showPoints(bool yes)
{
for(int i = 0; i < pointsList.count(); i++)
{
if(yes)
pointsList[i]->show();
else
pointsList[i]->hide();
}
}
Thanks in advance for your help.