#include #include #include #include #include /** * @class MainWindow * @brief Main application window. * * This class mirrors the functionality of the Python MainWindow class. * It's a subclass of QMainWindow and overrides the event() and paintEvent() * methods to demonstrate event handling and painting. */ class MainWindow : public QMainWindow { public: /** * @brief Constructor for MainWindow. * @param parent The parent widget. */ explicit MainWindow(QWidget* parent = nullptr) : QMainWindow(parent) { // The Python __init__ is very simple, so we just call the parent constructor. } protected: /** * @brief Event handler to catch and process events. * @param e The event to handle. * @return True if the event was handled, false otherwise. * * This method is an override of the base QMainWindow::event(). * It checks for a WinIdChange event, which corresponds to the window getting its * native handle, similar to the Python script. */ bool event(QEvent* e) override { if (e->type() == QEvent::WinIdChange) { qDebug() << "--- MainWindow.event(), Window native handle created"; } return QMainWindow::event(e); } /** * @brief Paint event handler. * @param pe The paint event. * * This method is an override of the base QMainWindow::paintEvent(). * It's called when the widget needs to be repainted. */ void paintEvent(QPaintEvent* pe) override { qDebug() << "--- MainWindow.paintEvent called"; QMainWindow::paintEvent(pe); } }; /** * @brief Main entry point of the application. * @param argc The number of command-line arguments. * @param argv An array of command-line arguments. * @return The application exit code. */ int main(int argc, char *argv[]) { // Create the QApplication object. QApplication app(argc, argv); // Create an instance of our MainWindow class. MainWindow window; // Show the window on the screen. window.show(); // Start the application's event loop. return app.exec(); }