QGraphicsScene/QGraphicsView performance
-
Hi,
First of all, your paint methods will always be called when the view interacts with mouse unless you ignore the mouse events.
Secondly, paint ,as it stands, should only perform painting but as far as I see you do many things beyond painting. Maybe that's why your items are slow. Plus remember that they will much faster in release mode(in case if you are working in debug mode).
Finally, what's the renderer?
-
[quote author="zgulser" date="1297760455"]Finally, what's the renderer?
[/quote]QSvgRenderer instance pointer.
-
[quote author="Jorj" date="1297696052"]you are emitting signals during your paint method, if these are connected to the (im assuming) game logic, and trigger a redraw, you will get an infinite ish loop[/quote]
I commented emit stuff but CPU usage did not change.
-
As I can see now you mess up everything with everything.
- paint method should do only painting nothing else (performance reasons)
- sizeHint is hardcoded I doubt you reale need this
- boundingRect is wrong for sure.
- you messing around with properties when it is not needed (this is needed if code supposed to manipulate objects with unknown api/structure).
Maybe explain what this should show!
[EDIT: fixed list - use "*" instead of "-" as "bullets", Volker]
-
MarekR22
How should I implement boundingRect()?
Sample code please. -
Although it won't solve your problem totally, it should be something like;
@
void Item::setBoundingRect(const QRect& pBoundingRect)
{
mBoundingRect = pBoundingRect;
}const QRect& Item::getBoundingRect()
{
return mBoundingRect;
}const QRect& Item::boundingRect()
{
return getBoundingRect();
}
@ -
[quote author="onurozcelik" date="1297780179"]MarekR22
How should I implement boundingRect()?
Sample code please.[/quote]
The joke is that you don't have to. QGraphicsWidget returns boundingRect which in most cases should be ok.
But like I said describe what you are trying to achieve then we will show you how code should look like.
Note there is a class "QGraphicsSvgItem":http://doc.trolltech.com/latest/qgraphicssvgitem.html. Maybe this is enough for you. -
implementing boundingRect correctly solved the infinite repaint loop problem.
-
[quote author="zgulser" date="1297781851"]
Although it won't solve your problem totally, it should be something like;@
void Item::setBoundingRect(const QRect& pBoundingRect)
{
mBoundingRect = pBoundingRect;
}const QRect& Item::getBoundingRect()
{
return mBoundingRect;
}const QRect& Item::boundingRect()
{
return getBoundingRect();
}
@[/quote]For performance critical code, you should just inline the stuff above.