Solved Why is closeEvent() not invoked for my QWidget ?
-
Hello all and thanks for reading this post,
I recently started using Qt for desktop application development using VS2017.
I am creating a class that derives from QWidget, but the closeEvent() callback of that class is not called once click on the "x" of the newly created window (it is called for the main window class). To be clear: I have a main window that spawns an additional widget, whose class does not respond to closeEvent().
My code is posted below.
Thanks in advance!// this code is executed by the main window class thread to create the new widget/window widget_ptr = new QWidget(parent_ptr) ; vertical_layout_ptr = new QVBoxLayout(widget_ptr) ; vertical_layout_ptr->setSpacing(6) ; vertical_layout_ptr->setContentsMargins(16, 16, 16, 16) ; custom_plot_ptr = new QCustomPlot(widget_ptr) ; vertical_layout_ptr->addWidget(custom_plot_ptr) ; QSize size(600, 300) ; widget_ptr->resize(size) ; widget_ptr->setWindowFlag(Qt::Window) ; QSizePolicy size_policy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding) ; widget_ptr->setSizePolicy(size_policy) ; widget_ptr->show() ;
-
hi @tamirmichael and welcome.
you may have overwritten the closeEvent, but from what you posted, you create a default QWidget.
You will have to use an instance of your modified class
-
Thanks for responding. That makes perfect sense, I may have missed there!
I will to correct this once home, will post the results here.
Thanks again. -
Yes that was it. How could I not have seen that :-)