QGraphicsSceneMouseEvent compile error
-
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.htmlIn 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?
-
@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
-
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" ? -
@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 *).