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

ListView.onCountChanged does not behave correctly when prepending to the model

    XMLWordPrintable

Details

    • a60f8832425aafbe6c5e8be3c25fefc9f8f2f87b

    Description

      The intent is to create a ListView which always shows the last item in the list.

      To reproduce:

      Check out the self contained http://websvn.kde.org/trunk/KDE/kdepim/runtime/qml/kde/tests/qmlbreadcrumbnavigation/simple

      svn co svn://anonsvn.kde.org/home/kde/trunk/KDE/kdepim/runtime/qml/kde/tests/qmlbreadcrumbnavigation/simple

      build it.

      The left panel is a QTreeView with two items. The right shows a QML scene with a ListView showing the second item. A timer fires after 2 seconds to prepend a new item in the list. The QML scene has a slot onCountChanged to keep the list scrolled to the bottom, but it does not work. The displayed item on the right is the second item instead of the first.

      Note that you can hack the MainWindow.cpp to append instead of prepend, and that works. The view on the right does show the last item in the list.

      kde-devel@chimera:~/kde/src/KDE/kdepimkomo/runtime/qml/kde/tests/qmlbreadcrumbnavigation/simple(master)$ git diff mainwindow.cpp
      diff --git a/runtime/qml/kde/tests/qmlbreadcrumbnavigation/simple/mainwindow.cpp b/runtime/qml/kde/tests/qmlbreadcrumbnavigation/simple/mainwindow.cpp
      index e04f845..ca1c781 100644
      — a/runtime/qml/kde/tests/qmlbreadcrumbnavigation/simple/mainwindow.cpp
      +++ b/runtime/qml/kde/tests/qmlbreadcrumbnavigation/simple/mainwindow.cpp
      @@ -69,7 +69,7 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags f )
      void MainWindow::prependNewRow()

      { QStandardItem *item = new QStandardItem("New Item"); - m_model->insertRow(0, item); + m_model->appendRow(item); }

      void MainWindow::removeBottomRow()

      Attachments

        1. simple-after.png
          19 kB
          Stephen Kelly (Personal)
        2. simple-before.png
          18 kB
          Stephen Kelly (Personal)
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            martjone Martin Jones (closed Nokia identity) (Inactive)
            steveire Stephen Kelly (Personal)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes