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

QTreeView::selectedIndexes works incorrectly when column 0 is hidden

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 5.12.12, 5.15.7, 6.2.2
    • Widgets: Itemviews
    • None
    • All

      I have (these points are not nececssary to reproduce the bug, just to provide context):

      1. I have two QTreeViews inside a QSplitter
      2. Both tree views use the same model
      3. Tree views are synchronized with each other with connect(left, &QTreeView::expanded, right, &QTreeView::expand); etc

      Then (this is necessary)

      1. The model is QSortFilterProxyModel
      2. Source model has N columns
      3. The first QTreeView displays the first M columns
      4. The second QTreeView displays the last (N-M) columns (column 0 is hidden too - this is important)
      5. Both QTreeViews have drag&drop enabled

      The bug:

      1. Drag doesn't work for child indexes in the right QTreeView (works only for top-level indexes, i.e. the ones whose parent() is invalid)
      2. This happens because QAbstractItemViewPrivate::selectedDraggableIndexes ignores the child indexes. This in turn is because QTreeView::selectedIndexes() removes indexes whose parent is hidden.
            while (index.isValid() && !isIndexHidden(index))
                index = index.parent();
        
      3. QSortFilterProxyModel::parent() always returns an index with column() == 0, so if the column 0 is hidden, QTreeView::selectedIndexes always treats child indexes as hidden.
      4. However, the child index is visible (i.e. the user can see it on the screen) and is selectable so this behaviour is incorrect.

        1. mainwindow.cpp
          8 kB
        2. mainwindow.h
          0.3 kB
        For Gerrit Dashboard: QTBUG-99419
        # Subject Branch Project Status CR V

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            kalinnikov Vadim Kalinnikov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:

                There is 1 open Gerrit change