Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-84331

QTreeWidget: wrong insertion order after internal drag&drop

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 4.8.7, 5.6.3, 5.9.9, 5.12.8, 5.14.2
    • Widgets: Itemviews
    • None

    Description

      #include <QApplication>
      #include <QTreeWidget>
      
      int main(int argc, char **argv)
      {
        QApplication app(argc, argv);
      
        QTreeWidget widget;
        widget.setSelectionMode(QAbstractItemView::ExtendedSelection);
        widget.setDragDropMode(QAbstractItemView::InternalMove);
      
        for (int index = 0; index < 10; ++index)
        {
          auto item = new QTreeWidgetItem(&widget);
          item->setFlags(Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsDragEnabled);
          item->setText(0, QString::number(index));
        }
      
        widget.show();
      
        return QApplication::exec();
      }

      Select items 1, 3, 5, 7, 9 (in this order), drag and drop them below item 6.

      Expected result is 0, 2, 4, 6, 1, 3, 5, 7, 9, 8,
      but the actual one is 0, 2, 4, 6, 8, 1, 3, 9, 7, 5.

      What's going on: the persistent index — that should guide the insertions — is one of the selected and becomes invalid after the removals. Now QTreeWidget tries to insert at the position determined by the dropOn call (row 7); when it is not possible, it inserts at the end (items 1, 3), and when it becomes possible, the insertions produce a reversed sequence (items 5, 7, 9).

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            a.khlyustov a.khlyustov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes