Add virtual QWindow::closeEvent handler
The default implementation does nothing; the processing of accepted close events remains in the QWidget::event handler, so that subclasses don't have to call the super class in order to free window system resources and emit lastWindowClosed signals. QWidgetWindow::event is reimplemented to handle QEvent::Close as well, calling QWidgetPrivate::close_helper, which then delivers a separate QCloseEvent to the widget. The order of execution for widgets is after this change: 1) QWidgetWindow::event 2) QWidgetWindow::handleCloseEvent (calls QWidget::event/closeEvent) 3) QWindow::event 4) QWindow::closeEvent <- does nothing, not overridden 5) default cleanup handling in QWindow::event and for Qt Quick after the corresponding change in qtdeclarative: 1) QQuickWindow::event 2) QWindow::event 3) QQuickWindow::closeEvent <- emits closed 4) default cleanup handling in QWindow::event [ChangeLog][QtGui][QWindow] closeEvent has been added as a virtual function. Task-number: QTBUG-31019 Change-Id: I201f5ee9c6a73b949986648e3bd288d2c7898f28 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>bb10
parent
b8668257e6
commit
7db59f458b
|
|
@ -2234,7 +2234,7 @@ void QWindow::showNormal()
|
|||
quitting the application. Returns \c true on success, false if it has a parent
|
||||
window (in which case the top level window should be closed instead).
|
||||
|
||||
\sa destroy(), QGuiApplication::quitOnLastWindowClosed()
|
||||
\sa destroy(), QGuiApplication::quitOnLastWindowClosed(), closeEvent()
|
||||
*/
|
||||
bool QWindow::close()
|
||||
{
|
||||
|
|
@ -2319,6 +2319,19 @@ void QWindow::hideEvent(QHideEvent *ev)
|
|||
ev->ignore();
|
||||
}
|
||||
|
||||
/*!
|
||||
Override this to handle close events (\a ev).
|
||||
|
||||
The function is called when the window is requested to close. Call \l{QEvent::ignore()}
|
||||
on the event if you want to prevent the window from being closed.
|
||||
|
||||
\sa close()
|
||||
*/
|
||||
void QWindow::closeEvent(QCloseEvent *ev)
|
||||
{
|
||||
Q_UNUSED(ev);
|
||||
}
|
||||
|
||||
/*!
|
||||
Override this to handle any event (\a ev) sent to the window.
|
||||
Return \c true if the event was recognized and processed.
|
||||
|
|
@ -2395,6 +2408,7 @@ bool QWindow::event(QEvent *ev)
|
|||
#endif
|
||||
|
||||
case QEvent::Close:
|
||||
closeEvent(static_cast<QCloseEvent*>(ev));
|
||||
if (ev->isAccepted()) {
|
||||
Q_D(QWindow);
|
||||
bool wasVisible = isVisible();
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ class QMoveEvent;
|
|||
class QResizeEvent;
|
||||
class QShowEvent;
|
||||
class QHideEvent;
|
||||
class QCloseEvent;
|
||||
class QKeyEvent;
|
||||
class QMouseEvent;
|
||||
#if QT_CONFIG(wheelevent)
|
||||
|
|
@ -350,7 +351,7 @@ protected:
|
|||
|
||||
virtual void showEvent(QShowEvent *);
|
||||
virtual void hideEvent(QHideEvent *);
|
||||
// TODO Qt 6 - add closeEvent virtual handler
|
||||
virtual void closeEvent(QCloseEvent *);
|
||||
|
||||
virtual bool event(QEvent *) override;
|
||||
virtual void keyPressEvent(QKeyEvent *);
|
||||
|
|
|
|||
Loading…
Reference in New Issue