Function callbacks
Even though Qt 6 supports the signals and slots mechanism, some of the features in Qt 6 still use function callbacks, such as keyboard input, window resizing, graphics painting, and others. Since these events only need to be implemented once, there is no need to use the signals and slots mechanism.
How to do it…
Let’s get started by following this example:
- Create a Qt Widgets Application project, open up
mainwindow.h
, and add the following headers:#include <QDebug> #include <QResizeEvent> #include <QKeyEvent> #include <QMouseEvent>
- Then, declare these functions in
mainwindow.h
:public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); void resizeEvent(QResizeEvent *event); void keyPressEvent(QKeyEvent *event); void keyReleaseEvent(QKeyEvent *event); void mouseMoveEvent...