MousePressEvent()



  • @
    void MySquare::mousePressEvent(QGraphicsSceneMouseEvent * event)
    {
    update();
    QGraphicsItem::mousePressEvent(event);
    }
    @

    In this code , MySquare is a subclass of QGraphicsItem. I need to know why after handling mousePressEvent() in subclass it is passed to Base Class.......It works even without that line, then why it is passed as a standard coding procedure.

    [edit: added missing coding tags @ SGaist]


  • Lifetime Qt Champion

    Hi,

    Because sometimes base class implementation do something and it should still be done. Whether you need to call the base class implementation and when you need to call it depends on what it does, what you do and how you do it.



  • Thanks for the reply.... Can u give me a situation where it is required so i get a clear picture.....


  • Lifetime Qt Champion

    An example is the data method from QIdentityProxyModel. You generally reimplement it to handle your special cases and for the rest you return the original implementation value.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.