Behavior of paint method in QGraphicsItem
when i inherit QGraphicsItem class and implement paint method,i am getting a problem,
the paint method is being called twice.What is the reason??
@void Mouse::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
@ printf("i entered once:\n");
gives me the following output
i entered once:
i entered once:
What is the reason for this?And how can i avoid this...
/this is the code/
class Draw:public QGraphicsItem
QRectF boundingRect() const;
QPainterPath shape() const;
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,QWidget *widget);
QRectF Draw::boundingRect() const
QPainterPath Draw::shape() const
void Draw::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
int main(int argc, char *argv)
QApplication a(argc, argv);
Draw *mouse=new Draw();
scene.setSceneRect(0, 0, 500, 500);
view.setWindowTitle(QT_TRANSLATE_NOOP(QGraphicsView, "Colliding Mice"));
[EDIT: code formatting cleanup, Volker]
i don't think this is a problem. why do you bother this?
Can you modify your previous posts and fix the code snippets? Just put a '@' before the whole snippet, and another one after; not one on each line!
BTW, why do you care about this?
paint method will be called as many time as there is any need of referesh in your view, first its called when you are creating the object second time it will be called when you show it on your view. and it will be called many other time if you minized or maximized etc
"This article":http://thesmithfam.org/blog/2007/02/03/qt-improving-qgraphicsview-performance/ might help.