Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved QGraphicsSceneMouseEvent compile error

    General and Desktop
    2
    4
    324
    Loading More Posts
    • 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.
    • ademmler
      ademmler last edited by

      Hi,

      I am trying to understand MouseEvents. Right now those according a GraphicsView.
      For example this: https://doc.qt.io/qt-5/qtwidgets-graphicsview-elasticnodes-example.html

      In my minimal code I type in the header file.

      void mouseMoveEvent(QGraphicsSceneMouseEvent *event) override;
      

      And I get this compile error:

      */Users/ademmler/QtTryouts/QtMinimalImage/mainwindow.h:31: error: non-virtual member function marked 'override' hides virtual member function
      void mouseMoveEvent(QGraphicsSceneMouseEvent event) override;

      If I remove the override and use:

      void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
      

      I get this warning:
      *mainwindow.h:31:10: warning: 'MainWindow::mouseMoveEvent' hides overloaded virtual function
      qwidget.h:623:18: note: hidden overloaded virtual function 'QWidget::mouseMoveEvent' declared here: type mismatch at 1st parameter ('QMouseEvent *' vs 'QGraphicsSceneMouseEvent ')

      Any idea what I am doing wrong?

      1 Reply Last reply Reply Quote 0
      • Christian Ehrlicher
        Christian Ehrlicher Lifetime Qt Champion last edited by

        @ademmler said in QGraphicsSceneMouseEvent compile error:

        Any idea what I am doing wrong?

        The compiler tells you what's wrong. You overload mouseMoveEvent() but using the wrong parameter. Since your mainwindow derives from QMainWindow, the mouseMoveEvent needs QMouseEvent as parameter: https://doc.qt.io/qt-5/qwidget.html#mouseMoveEvent

        Qt has to stay free or it will die.

        ademmler 1 Reply Last reply Reply Quote 2
        • ademmler
          ademmler @Christian Ehrlicher last edited by

          @Christian-Ehrlicher

          in the official QT "Elastics node example" they do exactly the same:

          void mousePressEvent(QGraphicsSceneMouseEvent *event) override;
          void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override;
          

          I do not understand how using "QMouseEvent" should work with an "QGraphicsScene" than?
          is there an official example which shows the usage for a "QGraphicsScene" ?

          1 Reply Last reply Reply Quote 0
          • Christian Ehrlicher
            Christian Ehrlicher Lifetime Qt Champion last edited by

            @ademmler said in QGraphicsSceneMouseEvent compile error:

            in the official QT "Elastics node example" they do exactly the same:

            No, they do not - the derive from QGraphicsScene which has the function mouseMoveEvent(QGraphicsSceneMouseEvent *).

            Qt has to stay free or it will die.

            1 Reply Last reply Reply Quote 3
            • First post
              Last post