I'm new to QT. How are these functions automatically called if I didn't call them?
Maybe somewhere inside the parent class there are connections that somehow connect them and launch them?
I know there will be a default constructor here, but how are these functions called, if the default constructor is empty
class CustomItem : public QGraphicsItem{
public:
QRectF boundingRect() const override{
return QRectF(0, 0, 80, 80);
}
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override{
Q_UNUSED(option);
Q_UNUSED(widget);
painter->fillRect(boundingRect(),Qt::red);
}
}item;
Public methods can be called by anyone who has a pointer or reference to objects of your class.
Presumably objects of this type are added to a QGraphicsScene
, which among other things will call boundingRect
to determine how much space your CustomItem
occupies, and paint
when it needs to draw the part of the scene with that item.