<HTML>
<HEAD>
<TITLE>Re: [PyQt] QGraphicsScene/Item/View optimisation</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>I have had great success with QtGui.QGraphicsItemAnimation alleviating the same issues that you are looking at.<BR>
<BR>
It looks like that your PictureItem is returning a really large bounding box so that caching system is repainting all or most of them at every step. Sometime it helps in debugging to just draw the bounding rect in red or some other obvious color for each item.<BR>
<BR>
I added a debugging code to swap the color of picture items when they are repainted:<BR>
<BR>
def paint(self, painter, options, widget):<BR>
self.p += 1<BR>
x, y, w, h = self._computeRect()<BR>
if self.p % 2 == 0:<BR>
color = "blue"<BR>
else:<BR>
color = "white"<BR>
painter.fillRect(x, y, w, h, QtGui.QColor(color))<BR>
...<BR>
<BR>
My other suggestion (that doesn’t really help in this case) is not using a thread. You can always fake your thread with timers, in general threads are evil and difficult to debug. Since python has a global interpreter lock, timers are just as fast (unless you call a long running bit of non-python code)<BR>
<BR>
class FakeThread(QtCore.QObject):<BR>
def __init__(self, scene):<BR>
QtCore.QObject.__init__(self)<BR>
self.scene = scene<BR>
self.__x = 0<BR>
self.__y = 0<BR>
self.count = 0<BR>
self.timer = QtCore.QTimer(self)<BR>
self.timer.setInterval(100)<BR>
self.connect(self.timer, QtCore.SIGNAL("timeout()"), self.timeout)<BR>
self.timer.start()<BR>
<BR>
def timeout(self):<BR>
self.scene.setHeadPosition(self.__x, -self.__y)<BR>
self.__x += 3.6<BR>
self.__y += 1.8<BR>
self.count += 1<BR>
if self.count > 10000:<BR>
QtCore.quit()<BR>
<BR>
<BR>
On 2/6/09 7:34 AM, "Frédéric" <<a href="frederic.mantegazza@gbiloba.org">frederic.mantegazza@gbiloba.org</a>> wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>Le 5/2/2009, "Grissiom" <<a href="chaos.proton@gmail.com">chaos.proton@gmail.com</a>> a écrit:<BR>
<BR>
> I think you may try some CacheFlag or OptimizationFlag in QGraphicsView, see:<BR>
><BR>
><a href="http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qgraphicsview.html#CacheModeFlag-enum">http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qgraphicsview.html#CacheModeFlag-enum</a><BR>
><a href="http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qgraphicsview.html#OptimizationFlag-enum">http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qgraphicsview.html#OptimizationFlag-enum</a><BR>
<BR>
I tried these flags, but they didnt change anything :o(<BR>
<BR>
I attached a short example to show my problem. As soon as the crosshair<BR>
starts to move, the CPU goes to 100%!<BR>
<BR>
Any idea to improve that code?<BR>
<BR>
--<BR>
Frédéric<BR>
<BR>
</SPAN></FONT></BLOCKQUOTE>
</BODY>
</HTML>