I’m relatively new to Qt.
I am writing an application where I am generating a pseudorandom numbers and keys and I would like to seed the generators with random mouse movements captured within a QMainWindow. Additionally, I would like to be able to turn this feature off and on when the user presses a QButton.
From what I understand I should be able to use connect() and disconnect() to a signal in QMainWindow that is emitted when the user moves the mouse. Is this the best approach?
My problem is I’m not sure what signal I should connect to. I have searched the Qt Documentation but can’t find a signal that’s generated when the mouse is moved over a QWidget.
You have to override
void QWidget::mouseMoveEvent ( QMouseEvent * event )in yourQMainWindowto capture the mouse move events. see http://qt-project.org/doc/qt-4.8/qwidget.html#mouseMoveEventYou probably want to do an
event->ignore()in the override to allow propagation of the event.You also have to enable mouse tracking with
void setMouseTracking ( bool enable )to receive mouse move event when no button is pressed. see http://qt-project.org/doc/qt-4.8/qwidget.html#mouseTracking-prop