[SOLVED] Difference between QWidget::hide() and QWidget::close()
-
wrote on 25 Apr 2013, 08:55 last edited by
Hello,
I am little bit confused regarding difference between QWidget::hide() and QWidget::close().
What exactly happens if "I close and show a widget" and "I hide and show a widget" -
It's desribed quite clearly in "the documentation":http://qt-project.org/doc/qt-4.8/qwidget.html#close.
::hide() only makes the widget disappear. ::close() can even destroy it in some cases.
-
wrote on 25 Apr 2013, 09:05 last edited by
close and hide are two different things.
Close is typically done, when you click the cross in the upper right corner. If a widget has the flag delete on close, it will be deleted afterwards.
Hid just makes the widget hidden. -
wrote on 25 Apr 2013, 09:17 last edited by
bq. First it sends the widget a QCloseEvent. The widget is hidden if it accepts the close event. If it ignores the event, nothing happens. The default implementation of QWidget::closeEvent() accepts the close event.
This is QWidget::close() detail, so default behavior is, whenever the ::close() is called, it simply hides the widget, right.?
-
wrote on 25 Apr 2013, 09:19 last edited by
hide : we can reuse or display again
close : widget completely close. -
[quote author="aekam" date="1366881423"]This is QWidget::close() detail, so default behavior is, whenever the ::close() is called, it simply hides the widget, right.?[/quote]
Read the whole description. The point is: it might just hide the widget on close(), but if your settings in code are different, it might delete it completely, or even close the whole application.
If you need the widget later, use hide() or setVisible(false). If you need to destroy it, do it yourself. close() is to be used with care.
-
wrote on 25 Apr 2013, 09:34 last edited by
The difference is that when you close the widget, if the Qt::WA_DeleteOnClose flag is set, the widget is deleted and any other data that it stored along with it... If not, the close method is a fancier way to say hide :)
-
wrote on 25 Apr 2013, 09:36 last edited by
also, if it is the only window open in your application it quits the application... so as sierdzio said:
[quote author="sierdzio" date="1366881775"]
If you need the widget later, use hide() or setVisible(false). If you need to destroy it, do it yourself. close() is to be used with care.[/quote] -
wrote on 25 Apr 2013, 09:55 last edited by
Thank you all for information... :)
-
Hello,
I am little bit confused regarding difference between QWidget::hide() and QWidget::close().
What exactly happens if "I close and show a widget" and "I hide and show a widget" -
wrote on 6 Apr 2022, 07:19 last edited by
@QtTester said in [SOLVED] Difference between QWidget::hide() and QWidget::close():
usually:
hide() = close()I don't know why you are replying to a thread last updated a decade ago! But as stated in the answers above,
hide()
does notclose()
a widget....