Is there any way I can get notified when a user closes a QMdiSubWindow? I cannot find any signal in QMdiArea nor in QMdiSubWindow that suggests I can.
I think my only chance is by subclassing QMdiSubWindow and overriding the close event, but is there any other way?
Yes, there is another way : you can install an event-filter on the QMdiSubWindow you create :
MdiSubWindowEventFilter * p_mdiSubWindowEventFilter;
...
QMdiSubWindow * subWindow = mdiArea->addSubWindow(pEmbeddedWidget);
subWindow->installEventFilter(p_mdiSubWindowEventFilter);
subWindow->setAttribute(Qt::WA_DeleteOnClose, true); // not mandatory, depends if you manage subWindows lifetime
with
bool MdiSubWindowEventFilter::eventFilter(QObject * obj, QEvent * e)
{
switch (e->type())
{
case QEvent::Close:
{
QMdiSubWindow * subWindow = dynamic_cast<QMdiSubWindow*>(obj);
Q_ASSERT (subWindow != NULL);
//
// do what you want here
//
break;
}
default:
qt_noop();
}
return QObject::eventFilter(obj, e);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With