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. QGraphicsSceneMouseEvent compile error
Forum Updated to NodeBB v4.3 + New Features

QGraphicsSceneMouseEvent compile error

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 681 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.
  • ademmlerA Offline
    ademmlerA Offline
    ademmler
    wrote on last edited by
    #1

    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
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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 Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      ademmlerA 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        @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

        ademmlerA Offline
        ademmlerA Offline
        ademmler
        wrote on last edited by
        #3

        @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
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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 Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          3

          • Login

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