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

[Regression] A QTreeView with autoscroll should not scroll vertically if the selection model is by row

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P2: Important
    • None
    • 4.5.0
    • Widgets: Itemviews
    • None

    Description

      t4id: 250084

      If a subclass of QAbstractItemView is configured with autoscroll(true) and the selection mode select the whole row on selection, the autoscrolling should not scroll horizontally. The row are considered as a single entity so scrolling horizontally is a strange behavior.

      Here is an example to show the problem, if you click somewhere in the second column, you don't expect the view to scroll horitontally.

      #include <QtGui>
      #include <QtCore>

      int main(int argc, char **argv){
      QApplication app(argc, argv);
      QStandardItemModel model(10, 2);
      for (int row = 0; row < 10; ++row) {
      for (int column = 0; column < 2; ++column)

      { QStandardItem *item = new QStandardItem(QString("row %0, column %1 ").arg(row).arg(column)); model.setItem(row, column, item); }

      }

      QTreeView view;
      view.setAutoScroll(true);
      view.setAllColumnsShowFocus(true);
      view.setModel(&model);
      view.setColumnWidth(1, 200);
      view.setColumnWidth(2, 1000);
      view.show();
      return app.exec();
      }

      Here is a patch to avoid the horizontal scrolling when the selection model is by row:

      diff --git a/src/gui/itemviews/qabstractitemview.cpp b/src/gui/itemviews/qabstractitemview.cpp
      index 26bf20f..cbf31e5 100644
      — a/src/gui/itemviews/qabstractitemview.cpp
      +++ b/src/gui/itemviews/qabstractitemview.cpp
      @@ -2210,8 +2210,15 @@ void QAbstractItemView::timerEvent(QTimerEvent *event)
      d->delayedAutoScroll.stop();
      //end of the timer: if the current item is still the same as the one when the mouse press occurred
      //we only get here if there was no double click

      • if (d->pressedIndex.isValid() && d->pressedIndex == currentIndex())
      • scrollTo(d->pressedIndex);
        + if (d->pressedIndex.isValid() && d->pressedIndex == currentIndex())
        Unknown macro: {+ if (d->selectionBehavior == QAbstractItemView}

        }
        }

      @@ -2311,7 +2318,6 @@ bool QAbstractItemView::edit(const QModelIndex &index, EditTrigger trigger, QEve
      w->setFocus();
      return true;
      }
      -
      if (trigger == DoubleClicked)

      { d->delayedEditing.stop(); d->delayedAutoScroll.stop(); @@ -2339,6 +2345,8 @@ bool QAbstractItemView::edit(const QModelIndex &index, EditTrigger trigger, QEve if (lastTrigger == DoubleClicked && trigger == SelectedClicked) return false; + if (d->autoScroll) + scrollTo(index); // we may get a double click event later if (trigger == SelectedClicked) d->delayedEditing.start(QApplication::doubleClickInterval(), this); @@ -3154,8 +3162,15 @@ void QAbstractItemView::currentChanged(const QModelIndex &current, const QModelI }

      }
      if (isVisible() && current.isValid() && !d->autoScrollTimer.isActive()) {

      • if (d->autoScroll)
      • scrollTo(current);
        + if (d->autoScroll)
        Unknown macro: {+ if (d->selectionBehavior == QAbstractItemView}

        d->setDirtyRegion(visualRect(current));
        d->updateDirtyRegion();
        edit(current, CurrentChanged, 0);

      Attachments

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

        Activity

          People

            vfm Thierry Bastian (closed Nokia identity) (Inactive)
            jasmcdon Jason McDonald (Closed Nokia Identity. Please assign to "macadder" instead) (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes