Colliding Mice Qt 4 example question
-
There is a function in mouse.cpp
@void Mouse::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
@I didn't see it being called anywhere so decided to step in main(). The last line in main() is
@return app.exec();@when this line is executed, the code steps into the paint function. Who is sending in the arguments like QPainter* etc?
Also, this function declaration from mouse.cpp has these mysterious pointers without any name, e.g. QStyleOptionGraphicsItem *. I haven't seen that before. What does it mean to just have a pointer and no name?
thanks,
sb -
The method is executed when the widget/item is shown.
The method is virtual, so the signature must be retained. If you do not need an argument, you can omit a name for it. If you have a name, the compiler will generate a warning (unless you use Q_UNUSED).
-
That's a QGraphicsItem, right? The QGraphicsView framework will invoke the paint method every time it is necessary to draw your item, so you don't have to care about that, and will pass to it an initialized QPainter to draw.
[quote]Also, this function declaration from mouse.cpp has these mysterious pointers without any name, e.g. QStyleOptionGraphicsItem *. I haven’t seen that before. What does it mean to just have a pointer and no name?[/quote]
It simply means that you are not going to use those parameters.
-
Thank you both so much for the information!
sb