How to check if a qwidget is closed ?
-
I have a parent widget A and a child widget B, and the user has the capability to open and close widget B from widget A. How can I check is widget B is closed ?
I show widget B using the show command.
One of the things i am thinking to do is passing a variable to the constructor of widget B then update its value in the CloseEvent, but i am pretty sure there is an easier way.
Many thanks in advance,
-
Try QWidget::isVisible()
-
You can in closeEvent() of your widget B emit your own signal widgetBClose() and then connect to this signal in widget A and do what you want in this slot.
-
A closed QWidget is hidden (i.e. not visible on screen) by definition, so, as @Kxyu said, QWidget::isVisible() can indicate whether a QWidget is closed.
QWidget::close() is basically a combination of QWidget::closeEvent(), QWidget::hide(), and QObject::deleteLater() (if Qt::WA_DeleteOnClose is set).
-
Thank you all for your responses. For isVisible, the reason why I haven't used it is as I understood from the docs if a widget is covered by another window then it is not visible. So I was confused.
I will give it a shot and see. Let’s say a widget is open but covered by another window, would this window be visible or not ?
Many thanks,
-
Quoting the "doc of QWidget":http://doc.qt.nokia.com/stable/qwidget.html#visible-prop:
bq. A widget that happens to be obscured by other windows on the screen is considered to be visible.
The "covered by another widget" thing only happens with widgets which have a parent are covered by other widgets that have the same parent (quite a mouthful).
-
Thank you uranusjr :) Much appreciated.