Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. MousePressEvent()
Forum Update on Tuesday, May 27th 2025

MousePressEvent()

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vinothrajendran4
    wrote on 18 Feb 2015, 12:21 last edited by
    #1

    @
    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]

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 18 Feb 2015, 12:31 last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vinothrajendran4
        wrote on 18 Feb 2015, 12:55 last edited by
        #3

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

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 18 Feb 2015, 22:38 last edited by
          #4

          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.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          2/4

          18 Feb 2015, 12:31

          • Login

          • Login or register to search.
          2 out of 4
          • First post
            2/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved