Creating a custom window

To create a window(ed) application, we usually call the show() method on an instance of QWidget and that makes that widget, to be contained in a window of its own, along with its child widgets displayed in it.

A recap of such a simple application is as follows:

#include <QApplication>#include <QMainWindow>#include <QLabel>int main(int argc, char *argv[]){   QApplication a(argc, argv);   QMainWindow mainWindow;   mainWindow.show();   return a.exec();}

mainWindow here is an instance of QMainWindow, which is derived from QWidget. As such, by calling the show() method, a window will appear. If you were to replace QMainWindow with QLabel, this will still work.

But this style of writing applications is not the best. Instead, from ...

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.