From 9434a443f583ee559257504f72e70bac25d9c3fc Mon Sep 17 00:00:00 2001 From: Matthew Griffin <45285214+matthew-griffin@users.noreply.github.com> Date: Fri, 28 Jun 2019 09:40:11 +0100 Subject: [PATCH] Ensure that QCloseEvents can be vetoed by wx These events use a different convention from all the other ones in Qt and need to be ignored, rather than accepted, to prevent the default action from occurring. And these events are also sent to disabled windows, which are never supposed to receive them in wx API. Closes https://github.com/wxWidgets/wxWidgets/pull/1371 --- include/wx/qt/private/winevent.h | 2 +- src/qt/window.cpp | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/wx/qt/private/winevent.h b/include/wx/qt/private/winevent.h index 5137f6d00e..f29b329e67 100644 --- a/include/wx/qt/private/winevent.h +++ b/include/wx/qt/private/winevent.h @@ -104,7 +104,7 @@ protected: if ( !this->GetHandler()->QtHandleCloseEvent(this, event) ) Widget::closeEvent(event); else - event->accept(); + event->ignore(); } //wxContextMenuEvent diff --git a/src/qt/window.cpp b/src/qt/window.cpp index cabf652879..c67e9606ea 100644 --- a/src/qt/window.cpp +++ b/src/qt/window.cpp @@ -1557,12 +1557,17 @@ bool wxWindowQt::QtHandleChangeEvent ( QWidget *handler, QEvent *event ) return false; } +// Returns true if the closing should be vetoed and false if the window should be closed. bool wxWindowQt::QtHandleCloseEvent ( QWidget *handler, QCloseEvent *WXUNUSED( event ) ) { if ( GetHandle() != handler ) return false; - return Close(); + // This is required as Qt will still send out close events when the window is disabled. + if ( !IsEnabled() ) + return true; + + return !Close(); } bool wxWindowQt::QtHandleContextMenuEvent ( QWidget *WXUNUSED( handler ), QContextMenuEvent *event )