Event handlers

All QObjects have an event() method that receives events. For QWidgets, this method will relay the event object to more specific event handlers. It is possible to redefine what an event handler should do by sub-classing the widget of interest and re-implementing that event handler.

Let's create an application where we shall re-implement an event handler.

Create a folder containing the main.cpp, mainwindow.cpp, and mainwindow.h files. The mainwindow.h file should contain the following code:

#include <QMainWindow>#include <QMoveEvent>#include <QMainWindow>class MainWindow: public QMainWindow {   Q_OBJECT   public:       MainWindow(QWidget *parent = 0);   protected:       void moveEvent(QMoveEvent *event);};

In the preceding code, we have only ...

Get Getting Started with Qt 5 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.