Fix focus issue with property editor

This commit is contained in:
wmayer 2013-07-17 13:58:18 +02:00
parent 64890a4552
commit d47a4838b2
2 changed files with 18 additions and 2 deletions

View File

@ -36,7 +36,7 @@ using namespace Gui::PropertyEditor;
PropertyItemDelegate::PropertyItemDelegate(QObject* parent) PropertyItemDelegate::PropertyItemDelegate(QObject* parent)
: QItemDelegate(parent) : QItemDelegate(parent), pressed(false)
{ {
} }
@ -89,6 +89,16 @@ void PropertyItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
painter->setPen(savedPen); 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*/, QWidget * PropertyItemDelegate::createEditor (QWidget * parent, const QStyleOptionViewItem & /*option*/,
const QModelIndex & index ) const const QModelIndex & index ) const
{ {
@ -101,8 +111,9 @@ QWidget * PropertyItemDelegate::createEditor (QWidget * parent, const QStyleOpti
QWidget* editor = childItem->createEditor(parent, this, SLOT(valueChanged())); QWidget* editor = childItem->createEditor(parent, this, SLOT(valueChanged()));
if (editor && childItem->isReadOnly()) if (editor && childItem->isReadOnly())
editor->setDisabled(true); editor->setDisabled(true);
else if (editor) else if (editor && this->pressed)
editor->setFocus(); editor->setFocus();
this->pressed = false;
return editor; return editor;
} }

View File

@ -42,9 +42,14 @@ public:
virtual void setEditorData(QWidget *editor, const QModelIndex &index) const; virtual void setEditorData(QWidget *editor, const QModelIndex &index) const;
virtual void setModelData (QWidget *editor, QAbstractItemModel *model, 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 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: public Q_SLOTS:
void valueChanged(); void valueChanged();
private:
mutable bool pressed;
}; };
} // namespace PropertyEditor } // namespace PropertyEditor