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

QTableView can't select full row if some columns were reordered, hidden

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 5.11.0
    • 5.5.1
    • Widgets: Itemviews
    • None
    • Windows 7, 64 bits, Microsoft Visual Studio 2008 SP1.

    Description

      Let's say we have a simplest model with two rows and three columns with fixed data. As in items-views tutorial. Pressing on a vertical header on any row selects all the row.

      But if hide first column and swap second and third, than pressing on the vertical header doesn't select a row but only one cell. Please see attached screenshots.

      It looks like the problem is caused by QTableViewPrivate::selectRow implementation. It tries to get visual spaces for logical but not visual indexes. The next patch fixes the problem for me. Hope it can help.

      Index: qtbase/src/widgets/itemviews/qtableview.cpp
      ===================================================================
      --- qtbase/src/widgets/itemviews/qtableview.cpp (revision 2)
      +++ qtbase/src/widgets/itemviews/qtableview.cpp (revision 4)
      @@ -3252,14 +3252,17 @@
                       command |= QItemSelectionModel::Current;
               }
      
      -        QModelIndex tl = model->index(qMin(rowSectionAnchor, row), logicalColumn(0), root);
      -        QModelIndex br = model->index(qMax(rowSectionAnchor, row), logicalColumn(model->columnCount(root) - 1), root);
      -        if ((verticalHeader->sectionsMoved() && tl.row() != br.row())
      -            || horizontalHeader->sectionsMoved()) {
      -            q->setSelection(q->visualRect(tl)|q->visualRect(br), command);
      -        } else {
      -            selectionModel->select(QItemSelection(tl, br), command);
      -        }
      +        //QModelIndex tl = model->index(qMin(rowSectionAnchor, row), logicalColumn(0), root);
      +        //QModelIndex br = model->index(qMax(rowSectionAnchor, row), logicalColumn(model->columnCount(root) - 1), root);
      +        //if ((verticalHeader->sectionsMoved() && tl.row() != br.row())
      +        //    || horizontalHeader->sectionsMoved()) {
      +        //    q->setSelection(q->visualRect(tl)|q->visualRect(br), command);
      +        //} else {
      +        //    selectionModel->select(QItemSelection(tl, br), command);
      +        //}
      +        QModelIndex upper = model->index(qMin(rowSectionAnchor, row), column, root);
      +        QModelIndex lower = model->index(qMax(rowSectionAnchor, row), column, root);
      +        selectionModel->select(QItemSelection(upper, lower), command|QItemSelectionModel::Rows);
           }
       }
      

      Attachments

        1. broken selection.png
          broken selection.png
          14 kB
        2. normal selection.png
          normal selection.png
          23 kB
        3. sample.7z
          4 kB

        Issue Links

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

          Activity

            People

              SG House Vyacheslav Grigoryev
              SG House Vyacheslav Grigoryev
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes