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

QTreeView selection bug when there are hidden columns

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: P2: Important P2: Important
    • 4.6.0
    • 4.4.3
    • Widgets: Itemviews
    • None

      When you have a tree view with extended selections of the
      form:

      Column 1 | Column 2 | ... | Column k | ... | Column n

      (doesn't matter if expandable items or not). You will find that if you hide a column 'k' and drag from the blank viewport to select items moving up with the mouse, you will get the items twice. This is because QTreeViewPrivate::columnRanges returns more ranges than expected when there are hidden columns in the middle of ranges. For instance, this is what I get for a test case:

      Without the patch:

      selection is
      (QItemSelectionRange(QModelIndex(9,0,0x8109740,MySortFilterProxyModel(0x80888c0) ) , QModelIndex(9,2,0x8109740,MySortFilterProxyModel(0x80888c0) ) )
      ,

      QItemSelectionRange(QModelIndex(9,0,0x8109740,MySortFilterProxyModel(0x80888c0) ) , QModelIndex(9,2,0x8109740,MySortFilterProxyModel(0x80888c0) ) )
      )

      With the patch:

      selection is
      (QItemSelectionRange(QModelIndex(9,0,0x80f13c8,MySortFilterProxyModel(0x80c5968) ) , QModelIndex(9,2,0x80f13c8,MySortFilterProxyModel(0x80c5968) ) )
      )

      As you can see without the patch when asking for selection() on the
      selection model you get twice the same range (what makes for example
      drag & drop to have the same information twice).

      It is important to note that this happens when you drag from bottom
      (blank viewport) selecting items going up, but as shown here:

      Column 0 | Column 2 (Column 1 hidden)
      items
      items
      items
      x < click here (and move vertically up)

      if you click like this:

      Column 0 | Column 2
      items
      items
      items
      x < do not click here

      the algorithm will correctly create the ranges (you won't be able to
      reproduce) because the problem consists on the column 1 creating a new
      range (because it is hidden, and next logical column != column + 1, 0
      + 1 != 2).

      Proposed patch:
      http://media.ereslibre.es/2008/10/qtreeview-selection-columns-hidden.diff

      Test case example:
      http://media.ereslibre.es/2008/10/qtreeview-bugcase

      diff:

      diff --git a/src/gui/itemviews/qtreeview.cpp b/src/gui/itemviews/qtreeview.cpp
      index d5ca633..b7975be 100644
      — a/src/gui/itemviews/qtreeview.cpp
      +++ b/src/gui/itemviews/qtreeview.cpp
      @@ -3494,7 +3494,7 @@ QList<QPair<int, int> > QTreeViewPrivate::columnRanges(const QModelIndex &topInd
      current.first = -2; // -1 is not enough because -1+1 = 0
      current.second = -2;
      foreach(int logicalColumn, logicalIndexes) {

      • if (current.second + 1 != logicalColumn) {
        + if (current.second + 1 != logicalColumn && !header->isSectionHidden(current.second + 1)) {
        if (current.first != -2) {
        //let's save the current one
        ret += current;

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

            monsen Marius Bugge Monsen
            janichol Andy Nichols
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes