diff --git a/src/Gui/propertyeditor/PropertyItemDelegate.cpp b/src/Gui/propertyeditor/PropertyItemDelegate.cpp index fa5bb7db9e0e..b46c2ad23c3d 100644 --- a/src/Gui/propertyeditor/PropertyItemDelegate.cpp +++ b/src/Gui/propertyeditor/PropertyItemDelegate.cpp @@ -37,6 +37,8 @@ #include "PropertyItemDelegate.h" #include "PropertyItem.h" #include "PropertyEditor.h" +#include "MDIView.h" +#include "Tree.h" FC_LOG_LEVEL_INIT("PropertyView",true,true) @@ -124,6 +126,40 @@ bool PropertyItemDelegate::editorEvent (QEvent * event, QAbstractItemModel* mode return QItemDelegate::editorEvent(event, model, option, index); } +bool PropertyItemDelegate::eventFilter(QObject *o, QEvent *ev) +{ + if (ev->type() == QEvent::FocusOut) { + PropertyEditor *parentEditor = qobject_cast(this->parent()); + auto widget = qobject_cast(o); + if (widget && parentEditor && parentEditor->activeEditor + && widget != parentEditor->activeEditor) + { + // We event filter child QAbstractButton and QLabel of an editor, + // which requires special focus change in order to not mess up with + // QItemDelegate's logic. + QWidget *w = QApplication::focusWidget(); + // For some reason, Qt (5.15) on Windows will remove current focus + // before bringing up a modal dialog. + if (!w) + return false; + while (w) { // don't worry about focus changes internally in the editor + if (w == widget || w == parentEditor->activeEditor) + return false; + + // ignore focus change to 3D view or tree view, because, for + // example DlgPropertyLink is implemented as modeless dialog + // to allow selection in 3D and tree view. + if (qobject_cast(w)) + return false; + if (qobject_cast(w)) + return false; + w = w->parentWidget(); + } + } + } + return QItemDelegate::eventFilter(o, ev); +} + QWidget * PropertyItemDelegate::createEditor (QWidget * parent, const QStyleOptionViewItem & /*option*/, const QModelIndex & index ) const { diff --git a/src/Gui/propertyeditor/PropertyItemDelegate.h b/src/Gui/propertyeditor/PropertyItemDelegate.h index f7f8a659e7bb..5cdc59f403b5 100644 --- a/src/Gui/propertyeditor/PropertyItemDelegate.h +++ b/src/Gui/propertyeditor/PropertyItemDelegate.h @@ -44,6 +44,9 @@ class PropertyItemDelegate : public QItemDelegate virtual QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const; virtual bool editorEvent (QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem& option, const QModelIndex& index); +protected: + bool eventFilter(QObject *, QEvent *); + public Q_SLOTS: void valueChanged();