PySide Bugzilla Closed for New Bugs

PySide is now a Qt Add-on and uses the Qt Project's JIRA Bug Tracker instead of this Bugzilla instance. This Bugzilla is left for reference purposes.

Bug 556 - QGraphicsScene.addItem performs very poorly when the scene has >10000 items
: QGraphicsScene.addItem performs very poorly when the scene has >10000 items
Status: CLOSED FIXED
Product: PySide
Classification: Unclassified
Component: QtGui
: 1.0.0 beta1
: All All
: P3 normal
Assigned To: renato filho
:
:
:
  Show dependency treegraph
 
Reported: 2010-12-17 22:09 EET by Farsmo
Modified: 2011-01-21 15:44 EET (History)
9 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Farsmo 2010-12-17 22:09:57 EET
The following Python test case runs very slowly:

from PySide.QtCore import *
from PySide.QtGui import *
import math

class View(QGraphicsView):
    def __init__(self,n):
        super(View,self).__init__()
        self.setScene(QGraphicsScene())
        self.scene().setItemIndexMethod(QGraphicsScene.NoIndex)
        self.scene().setSceneRect(0,0,n,n)

        self.setTransformationAnchor(QGraphicsView.AnchorUnderMouse)
        self.setResizeAnchor(QGraphicsView.AnchorViewCenter)

        for x in xrange(n):
            print x*n,"items so far"
            for y in xrange(n):
                self.scene().addRect(x,y,0.5,0.5)

        self.setMinimumSize(400,400)

    def wheelEvent(self,e):
        k = math.pow(2.0, e.delta()/240.0)
        self.scale(k,k)

if __name__=="__main__":
    import sys
    app = QApplication(sys.argv)
    widget = View(1000)
    widget.show()
    exit(app.exec_())


On the other hand, the corresponding C++ code runs orders of magnitude faster,
because performance does not degrade over time:

(compile with CONFIG += console)

#include <QtGui>
#include <cmath>

struct View : public QGraphicsView {
    View(int n) {
    setScene(new QGraphicsScene());
    scene()->setItemIndexMethod(QGraphicsScene::NoIndex);
    scene()->setSceneRect(0,0,n,n);

    for (int i=0; i<n; i++) {
        qDebug()<<i*n<<"items so far";
        for (int j=0; j<n; j++)
        scene()->addRect(i,j,0.5,0.5);
    }

    setMinimumSize(400,400);
    }
    void wheelEvent(QWheelEvent* e) {
    double k = pow(2.0, e->delta()/240.0);
    scale(k,k);
    }
};

int main(int argc,char **argv) {
    QApplication app(argc,argv);
    View widget(1000);
    widget.show();
    return app.exec();
}
Comment 1 Matti Airas 2010-12-20 12:06:13 EET
Thanks for the bug report! Indeed, shouldn't have such behaviour.

I'm prioritizing this P3 - this will be fixed once the preceding P2/P3 bugs
have been dealt with.
Comment 2 renato filho 2011-01-13 09:13:00 EET
*** Bug 568 has been marked as a duplicate of this bug. ***
Comment 3 renato filho 2011-01-13 10:53:30 EET
Fixed on shiboken commit:

commit b719c4e8b9238ea8c4d1e022cf597e8cb628f5d7
Author: Renato Araujo Oliveira Filho <renato.filho@openbossa.org>
Date:   Wed Jan 12 19:30:23 2011 -0300
Comment 4 renato filho 2011-01-21 15:44:45 EET
release beta4