Reputation: 73
My MainWindow creates a QWidget called wid. How can I create a slot that is activated when that widget is closed?
Upvotes: 0
Views: 298
Reputation: 1305
You can subclass the QWidget and add the functionality as follows:
class CloseableWidget: public QWidget {
Q_OBJECT
public:
CloseableWidget(QWidget* parent = nullptr): QWidget(parent) {}
signals:
void onClose(QCloseEvent* e);
protected:
void closeEvent(QCloseEvent* e) override {
emit onClose(e);
}
};
and create instance of CloseableWidget
instead of QWidget
, Now you can connect your wid
with onClose
signal with a slot of MainWindow.
Upvotes: 1