Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTreeView, Qt::ItemIsEditable and Double-Clicking Issues.
Forum Updated to NodeBB v4.3 + New Features

QTreeView, Qt::ItemIsEditable and Double-Clicking Issues.

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 1 Posters 2.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • webzoidW Offline
    webzoidW Offline
    webzoid
    wrote on last edited by webzoid
    #1

    I have a QTreeView in which certain items are in-place editable and others are not.

    Those items which are editable return the Qt::ItemIsEditable flag and those which are not do not return this flag as part of the Qt::ItemFlags <class>::flags(const QModelIndex &index) const overridden. The items which are not editable have a pop-up dialog which is displayed as part of the QTreeView::doubleClicked(QModelIndex) signal.

    So, the issue I'm having is that initially, if I double-click on any of the Qt::ItemIsEditable items and edit them in-place, all is well. As soon as I double-click on a non Qt::ItemIsEditable item, 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 mouseDoubleClicked function in my subclassed QTreeView but still no joy.

    webzoidW 1 Reply Last reply
    0
    • webzoidW webzoid

      I have a QTreeView in which certain items are in-place editable and others are not.

      Those items which are editable return the Qt::ItemIsEditable flag and those which are not do not return this flag as part of the Qt::ItemFlags <class>::flags(const QModelIndex &index) const overridden. The items which are not editable have a pop-up dialog which is displayed as part of the QTreeView::doubleClicked(QModelIndex) signal.

      So, the issue I'm having is that initially, if I double-click on any of the Qt::ItemIsEditable items and edit them in-place, all is well. As soon as I double-click on a non Qt::ItemIsEditable item, 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 mouseDoubleClicked function in my subclassed QTreeView but still no joy.

      webzoidW Offline
      webzoidW Offline
      webzoid
      wrote on last edited by
      #2

      Ok, so I've narrowed the issue down to the qabstractitemview.cpp file and specifically, the function below.

      When I attempt to edit a Qt::ItemIsEditable item first, the w = delegate->createEditor(viewport, options, index); call from below returns a QLineEdit widget and the in-place editing works. If I then edit an item which shows a dialog, then go back and attempt to edit another Qt::ItemIsEditable item, the next time this w = delegate->createEditor(viewport, options, index); is called, the result is that w is null yet the parameters passed into the createEditor function 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;
      }
      
      1 Reply Last reply
      0
      • webzoidW Offline
        webzoidW Offline
        webzoid
        wrote on last edited by
        #3

        RESOLVED

        As it turns out, the dialog I was showing had a custom QWidget with its own custom editor and I was calling QItemEditorFactory::setDefaultFactory in the widgets constructor.

        Calling QItemEditorFactory::setDefaultFactory(nullptr) in the destructor for this widget resolves the problem - the QTreeView item in-place editor continues to work regardless of whether I open a dialog.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved