QTreeView, Qt::ItemIsEditable and Double-Clicking Issues.
-
I have a
QTreeViewin which certain items are in-place editable and others are not.Those items which are editable return the
Qt::ItemIsEditableflag and those which are not do not return this flag as part of theQt::ItemFlags <class>::flags(const QModelIndex &index) constoverridden. The items which are not editable have a pop-up dialog which is displayed as part of theQTreeView::doubleClicked(QModelIndex)signal.So, the issue I'm having is that initially, if I double-click on any of the
Qt::ItemIsEditableitems and edit them in-place, all is well. As soon as I double-click on a nonQt::ItemIsEditableitem, see the dialog and then close it again, the in-place editing system stops working.UPDATE
In fact, all in-place edit triggers stop working if a non-editable item is double-clicked. I've tried overriding the
mouseDoubleClickedfunction in my subclassedQTreeViewbut still no joy. -
I have a
QTreeViewin which certain items are in-place editable and others are not.Those items which are editable return the
Qt::ItemIsEditableflag and those which are not do not return this flag as part of theQt::ItemFlags <class>::flags(const QModelIndex &index) constoverridden. The items which are not editable have a pop-up dialog which is displayed as part of theQTreeView::doubleClicked(QModelIndex)signal.So, the issue I'm having is that initially, if I double-click on any of the
Qt::ItemIsEditableitems and edit them in-place, all is well. As soon as I double-click on a nonQt::ItemIsEditableitem, see the dialog and then close it again, the in-place editing system stops working.UPDATE
In fact, all in-place edit triggers stop working if a non-editable item is double-clicked. I've tried overriding the
mouseDoubleClickedfunction in my subclassedQTreeViewbut still no joy.Ok, so I've narrowed the issue down to the
qabstractitemview.cppfile and specifically, the function below.When I attempt to edit a
Qt::ItemIsEditableitem first, thew = delegate->createEditor(viewport, options, index);call from below returns aQLineEditwidget and the in-place editing works. If I then edit an item which shows a dialog, then go back and attempt to edit anotherQt::ItemIsEditableitem, the next time thisw = delegate->createEditor(viewport, options, index);is called, the result is thatwisnullyet the parameters passed into thecreateEditorfunction appear to be identical.The search continues...
QWidget *QAbstractItemViewPrivate::editor(const QModelIndex &index, const QStyleOptionViewItem &options) { Q_Q(QAbstractItemView); QWidget *w = editorForIndex(index).widget.data(); if (!w) { QAbstractItemDelegate *delegate = delegateForIndex(index); if (!delegate) return 0; w = delegate->createEditor(viewport, options, index); if (w) { w->installEventFilter(delegate); QObject::connect(w, SIGNAL(destroyed(QObject*)), q, SLOT(editorDestroyed(QObject*))); delegate->updateEditorGeometry(w, options, index); delegate->setEditorData(w, index); addEditor(index, w, false); if (w->parent() == viewport) QWidget::setTabOrder(q, w); // Special cases for some editors containing QLineEdit QWidget *focusWidget = w; while (QWidget *fp = focusWidget->focusProxy()) focusWidget = fp; #if QT_CONFIG(lineedit) if (QLineEdit *le = qobject_cast<QLineEdit*>(focusWidget)) le->selectAll(); #endif #if QT_CONFIG(spinbox) if (QSpinBox *sb = qobject_cast<QSpinBox*>(focusWidget)) sb->selectAll(); else if (QDoubleSpinBox *dsb = qobject_cast<QDoubleSpinBox*>(focusWidget)) dsb->selectAll(); #endif } } return w; } -
RESOLVED
As it turns out, the dialog I was showing had a custom
QWidgetwith its own custom editor and I was callingQItemEditorFactory::setDefaultFactoryin the widgets constructor.Calling
QItemEditorFactory::setDefaultFactory(nullptr)in the destructor for this widget resolves the problem - theQTreeViewitem in-place editor continues to work regardless of whether I open a dialog.