#includeint main(int argc, char *argv[]) { QApplication app(argc, argv); QWidget *widget = new QWidget(); widget->show(); return app.exec(); }
#includeclass MyWidget : public QWidget { public: MyWidget(QWidget *parent = nullptr) : QWidget(parent) {} }; int main(int argc, char *argv[]) { QApplication app(argc, argv); MyWidget *widget = new MyWidget(); widget->show(); return app.exec(); }
#includeThis example creates a custom widget that responds to the Escape key by closing itself. Package library: Qt GUI#include class MyWidget : public QWidget { public: MyWidget(QWidget *parent = nullptr) : QWidget(parent) {} protected: void keyPressEvent(QKeyEvent *event) override { if (event->key() == Qt::Key_Escape) { close(); } } }; int main(int argc, char *argv[]) { QApplication app(argc, argv); MyWidget *widget = new MyWidget(); widget->show(); return app.exec(); }