I am trying to use the Qt Graphics Framework to draw a graph with a large number of nodes (2000+). Using the QGraphicsView and the QGraphicsScene I can easily draw large number of ellipses with the addEllipse() method, but changing the color of the items with setBrush() is way too slow. I have also tried using QGraphicsPixmapItem and then just switch the pixmap to change color but this also does not work. Can you give me any advice how to accomplish this? Is using OpenGL the only way I can get better performance?
Thanks a lot.
Edit: I do not have the brush example. Will post it later. The code just swap brushes of the ellipse nothing more,
Edit: Pixmap example (Code is in python with PyQt):
def startTest(self):
self.n = 1000
self.c = 1
self.scene = QtGui.QGraphicsScene()
self.scene.setSceneRect(0,0,500,500)
self.graphicsView.setScene(self.scene)
self.redPix = QtGui.QPixmap(5, 5)
self.redPix.fill(QtGui.QColor(255,0,0))
self.blackPix = QtGui.QPixmap(5, 5)
self.blackPix.fill(QtGui.QColor(0,0,0))
for i in range(0,self.n):
temp = QtGui.QGraphicsPixmapItem(self.redPix)
temp.setPos(random.uniform(10, 490),random.uniform(10, 490))
self.scene.addItem(temp)
def updateNodes(self):
if self.c:
for i in self.scene.items():
i.setPixmap(self.blackPix)
self.c = 0
else:
for i in self.scene.items():
i.setPixmap(self.redPix)
self.c = 1