diff --git a/src/Gui/propertyeditor/PropertyEditor.cpp b/src/Gui/propertyeditor/PropertyEditor.cpp index 22b5144a122c..09ae4f10439f 100644 --- a/src/Gui/propertyeditor/PropertyEditor.cpp +++ b/src/Gui/propertyeditor/PropertyEditor.cpp @@ -53,6 +53,9 @@ PropertyEditor::PropertyEditor(QWidget *parent) QStyleOptionViewItem opt = viewOptions(); this->background = opt.palette.dark(); this->groupColor = opt.palette.color(QPalette::BrightText); + + connect(this, SIGNAL(activated(const QModelIndex &)), this, SLOT(onItemActivated(const QModelIndex &))); + connect(this, SIGNAL(clicked(const QModelIndex &)), this, SLOT(onItemActivated(const QModelIndex &))); } PropertyEditor::~PropertyEditor() @@ -127,8 +130,17 @@ void PropertyEditor::currentChanged ( const QModelIndex & current, const QModelI QTreeView::currentChanged(current, previous); if (previous.isValid()) closePersistentEditor(model()->buddy(previous)); - if (current.isValid()) - openPersistentEditor(model()->buddy(current)); + + // DO NOT activate editor here, use onItemActivate() which response to + // signals of activated and clicked. + // + // if (current.isValid()) + // openPersistentEditor(model()->buddy(current)); +} + +void PropertyEditor::onItemActivated ( const QModelIndex & index ) +{ + openPersistentEditor(model()->buddy(index)); } void PropertyEditor::reset() diff --git a/src/Gui/propertyeditor/PropertyEditor.h b/src/Gui/propertyeditor/PropertyEditor.h index c4e48cb42001..36eecd0850d4 100644 --- a/src/Gui/propertyeditor/PropertyEditor.h +++ b/src/Gui/propertyeditor/PropertyEditor.h @@ -81,6 +81,9 @@ class PropertyEditor : public QTreeView QColor groupTextColor() const; void setGroupTextColor(const QColor& c); +public Q_SLOTS: + void onItemActivated(const QModelIndex &index); + protected: virtual void closeEditor (QWidget * editor, QAbstractItemDelegate::EndEditHint hint); virtual void commitData (QWidget * editor); diff --git a/src/Gui/propertyeditor/PropertyItemDelegate.cpp b/src/Gui/propertyeditor/PropertyItemDelegate.cpp index cb5875ddcc20..ec6872eb7aa0 100644 --- a/src/Gui/propertyeditor/PropertyItemDelegate.cpp +++ b/src/Gui/propertyeditor/PropertyItemDelegate.cpp @@ -38,6 +38,8 @@ using namespace Gui::PropertyEditor; PropertyItemDelegate::PropertyItemDelegate(QObject* parent) : QItemDelegate(parent), pressed(false) { + connect(this, SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)), + this, SLOT(editorClosed(QWidget*))); } PropertyItemDelegate::~PropertyItemDelegate() @@ -112,6 +114,10 @@ bool PropertyItemDelegate::editorEvent (QEvent * event, QAbstractItemModel* mode return QItemDelegate::editorEvent(event, model, option, index); } +void PropertyItemDelegate::editorClosed(QWidget *editor) { + editor->close(); +} + QWidget * PropertyItemDelegate::createEditor (QWidget * parent, const QStyleOptionViewItem & /*option*/, const QModelIndex & index ) const { @@ -126,8 +132,14 @@ QWidget * PropertyItemDelegate::createEditor (QWidget * parent, const QStyleOpti editor->setAutoFillBackground(true); if (editor && childItem->isReadOnly()) editor->setDisabled(true); - else if (editor && this->pressed) + // else if (editor && this->pressed) + else if(editor) { + // We changed the way editor is activated in PropertyEditor (in response + // of signal activated and clicked), so now we should grab focus + // regardless of "preseed" or not (e.g. when activated by keyboard + // enter) editor->setFocus(); + } this->pressed = false; return editor; } diff --git a/src/Gui/propertyeditor/PropertyItemDelegate.h b/src/Gui/propertyeditor/PropertyItemDelegate.h index 236020bd21a7..23d0a41f3c2d 100644 --- a/src/Gui/propertyeditor/PropertyItemDelegate.h +++ b/src/Gui/propertyeditor/PropertyItemDelegate.h @@ -47,6 +47,7 @@ class PropertyItemDelegate : public QItemDelegate public Q_SLOTS: void valueChanged(); + void editorClosed(QWidget *); private: mutable bool pressed;