I'm searching for something like the finished-signal from QDialog
, only for QWidget
. The reason is, I disable my toolbar once the widget pops up (which isn't a problem at all) and I want the toolbar to be enabled again, once the widget is closed.
I also can't override the close-Event of that widget, because then we would have GUI-code in business-classes.
QWidget doesn't have many signals really, according to the documentation it has a grand total of 2. However, that doesn't mean you can't specify a signal yourself and use it, which is probably the best method.
You can set the widget to be deleted on close, and then listen to its
destroyed
signal:That only works if you're not interested in the widget contents though. At the point
destroyed()
is emitted, the widget isn't aQWidget
anymore, just aQObject
(asdestroyed()
is emitted from~QObject
), so you can't cast the argumentQObject*
toQWidget
anymore.A simple alternative might be to wrap your widget with a
QDialog
.In your Widget class, you can add your own signal that others can connect to. Then override the
closeEvent()
method. Don't worry about overriding this method, this kind of situation is exactly the right reason do to it.In the
closeEvent
method trigger your signal: