上QQ阅读APP看书,第一时间看更新
How it works...
Qt 5 objects, especially the main window, has a dozen of built-in callbacks that exist as virtual functions. These functions can be overridden to perform your intended behavior when called. Qt 5 may invoke these callback functions when its expected condition has been met, such as a keyboard button has been pressed, the mouse cursor has been moved, the window has been resized, and so on.
The functions that we declared in the mainwindow.h file are virtual functions that are built into the QWidget class. We are just overriding it with our own code to define its new behavior when it's called.
Do take note that you must call setMouseTracking(true) for both MainWindow and centralWidget for the mouseMoveEvent() callback to work.