
Originally Posted by
camel
Hey,
I just changed your source a bit so that the boundingrects and shapes are only calculated once...
check if that helps with the performance a bit...
(since I cannot realy judge it here... :-)
I also found that the grid-color-problem is lessend (but not gone) when you fill the rect in the draw background,
And the error is gone completely when you turn off anti-aliasing.
Might be a Qt-Bug :-/
Anyways, my version of your code :-)
#include <QtGui>
#include <cmath>
{
public:
....
#include <QtGui>
#include <cmath>
class GridScene : public QGraphicsScene
{
public:
....
To copy to clipboard, switch view to plain text mode
I am really thankful to your support. 
Yeah you are right. The colouring is gone without antialiasing. But I also experimented with one more thing.
I did this in drawBackground() which didn't alter much
void GridScene
::drawBackground(QPainter *p,
const QRectF
& rect
) const {
QPainter::RenderHints rh
= p
->renderHints
();
p->setRenderHints(0);
...
p->setRenderHints(rh);
}
void GridScene::drawBackground(QPainter *p, const QRectF& rect) const
{
QPainter::RenderHints rh = p->renderHints();
p->setRenderHints(0);
...
p->setRenderHints(rh);
}
To copy to clipboard, switch view to plain text mode
Should be Qt bug I believe.
Calculating bounding rect beforehand did show improvement in performance. But I feel the main performance blow is in drawBackground(). Somehow I feel that drawBackground() is called more than required times which is causing all these. For example try with this
view->setCacheMode(QGraphicsView::CacheBackground);
To copy to clipboard, switch view to plain text mode
The performance improves but the background corrupts when we scroll. Also as I pointed in my last but one post, increasing bounding rect of resistor so that it covers node also sigificantly improved performance. This suggests that the rects are not ORred properly before updating that region. ( I may be wrong, correct me if I am)
Well to exactly solve this we need to profile the code (with profiling enabled for qt lib) or use some intelligent techniques (which I am not aware of )
Bookmarks