diff --git a/src/Gui/propertyeditor/PropertyItemDelegate.cpp b/src/Gui/propertyeditor/PropertyItemDelegate.cpp index 2aa58bffb..f6ca91506 100644 --- a/src/Gui/propertyeditor/PropertyItemDelegate.cpp +++ b/src/Gui/propertyeditor/PropertyItemDelegate.cpp @@ -36,7 +36,7 @@ using namespace Gui::PropertyEditor; PropertyItemDelegate::PropertyItemDelegate(QObject* parent) - : QItemDelegate(parent) + : QItemDelegate(parent), pressed(false) { } @@ -89,6 +89,16 @@ void PropertyItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem & painter->setPen(savedPen); } +bool PropertyItemDelegate::editorEvent (QEvent * event, QAbstractItemModel* model, + const QStyleOptionViewItem& option, const QModelIndex& index) +{ + if (event && event->type() == QEvent::MouseButtonPress) + this->pressed = true; + else + this->pressed = false; + return QItemDelegate::editorEvent(event, model, option, index); +} + QWidget * PropertyItemDelegate::createEditor (QWidget * parent, const QStyleOptionViewItem & /*option*/, const QModelIndex & index ) const { @@ -101,8 +111,9 @@ QWidget * PropertyItemDelegate::createEditor (QWidget * parent, const QStyleOpti QWidget* editor = childItem->createEditor(parent, this, SLOT(valueChanged())); if (editor && childItem->isReadOnly()) editor->setDisabled(true); - else if (editor) + else if (editor && this->pressed) editor->setFocus(); + this->pressed = false; return editor; } diff --git a/src/Gui/propertyeditor/PropertyItemDelegate.h b/src/Gui/propertyeditor/PropertyItemDelegate.h index b3086f65e..236020bd2 100644 --- a/src/Gui/propertyeditor/PropertyItemDelegate.h +++ b/src/Gui/propertyeditor/PropertyItemDelegate.h @@ -42,9 +42,14 @@ public: virtual void setEditorData(QWidget *editor, const QModelIndex &index) const; virtual void setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex& index ) const; virtual QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const; + virtual bool editorEvent (QEvent *event, QAbstractItemModel *model, + const QStyleOptionViewItem& option, const QModelIndex& index); public Q_SLOTS: void valueChanged(); + +private: + mutable bool pressed; }; } // namespace PropertyEditor