From 652e833fba18eed37e31239d703334343eba7630 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Thu, 14 Nov 2019 17:28:37 +1300 Subject: [PATCH] Qt 5.12.5+: fixed an issue wit our property editor that would crash OpenCOR (#2211). --- .../Core/src/propertyeditorwidget.cpp | 25 ++++++++++++++----- .../Core/src/propertyeditorwidget.h | 2 ++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/plugins/miscellaneous/Core/src/propertyeditorwidget.cpp b/src/plugins/miscellaneous/Core/src/propertyeditorwidget.cpp index f19e9c8088..0456816a9c 100644 --- a/src/plugins/miscellaneous/Core/src/propertyeditorwidget.cpp +++ b/src/plugins/miscellaneous/Core/src/propertyeditorwidget.cpp @@ -45,6 +45,7 @@ along with this program. If not, see . #include #include #include +#include #include //============================================================================== @@ -2031,6 +2032,15 @@ void PropertyEditorWidget::checkCheckState(QStandardItem *pItem) //============================================================================== +void PropertyEditorWidget::updateFocusProxy() +{ + // Set our property's editor as our focus proxy + + setFocusProxy(mPropertyEditor); +} + +//============================================================================== + void PropertyEditorWidget::editorOpened(QWidget *pEditor) { // Keep track of some information about the property @@ -2058,14 +2068,17 @@ void PropertyEditorWidget::editorOpened(QWidget *pEditor) // Next, we need to use the property's editor as our focus proxy and make // sure that it immediately gets the focus - // Note: if we were not to immediately give the focus to our editor, then - // the central widget would give the focus to the previously focused - // widget (see CentralWidget::updateGui()), which is clearly not what - // we want... - - setFocusProxy(pEditor); + // Note #1: if we were not to immediately give the focus to our editor, then + // the central widget would give the focus to the previously + // focused widget (see CentralWidget::updateGui()), which is + // clearly not what we want... + // Note #2: starting with Qt 5.12.5, we can't immediately set the property's + // editor as our focus proxy (!?). This will indeed crash OpenCOR! + // So, instead, we set it through a single shot... pEditor->setFocus(); + + QTimer::singleShot(0, this, &PropertyEditorWidget::updateFocusProxy); } //============================================================================== diff --git a/src/plugins/miscellaneous/Core/src/propertyeditorwidget.h b/src/plugins/miscellaneous/Core/src/propertyeditorwidget.h index 2cc56e7307..75c0b00cda 100644 --- a/src/plugins/miscellaneous/Core/src/propertyeditorwidget.h +++ b/src/plugins/miscellaneous/Core/src/propertyeditorwidget.h @@ -472,6 +472,8 @@ private slots: void checkCheckState(QStandardItem *pItem); + void updateFocusProxy(); + void editorOpened(QWidget *pEditor); void editorClosed();