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

Removing an item from QQuickStackLayout does not decrement the current index

    XMLWordPrintable

Details

    • Bug
    • Resolution: Cannot Reproduce
    • P2: Important
    • None
    • 5.12.0, 5.12.1, 5.12.2, 5.12.3, 5.12.4
    • Quick: Layouts
    • None
    • macOS, Windows

    Description

      On a project I'm working on, this situation causes an assert in QQuickStackLayout because when it tries to use `itemAt` with the current index, `itemAt` returns `nullptr`. The assertion is in `QQuickStackLayout::rearrange(const QSizeF &newSize)`.

      I could not reproduce the crash with a sample project, the assert might be caused by something else. But the behavior where the currentIndex doesn't change happens in both the sample code and the project I'm working on.

      import QtQuick 2.12
      import QtQuick.Layouts 1.4
      import QtQuick.Controls 2.4ApplicationWindow {
          id: mainWindow
          width: 640
          height: 480
          title: "Window #1"
          color: "#495567"    StackLayout {
              id: sl
              anchors {
                  top: parent.top
                  left: parent.left
                  right: parent.right
                  bottom: btn.top
              }
              currentIndex: count - 1        Rectangle {
                  id: rect1
                  width: 300
                  height: 300
                  color: "red"
                  Layout.fillWidth: true
                  Layout.fillHeight: true
              }        Rectangle {
                  width: 300
                  height: 300
                  color: "green"
                  Layout.fillWidth: true
                  Layout.fillHeight: true
              }        Rectangle {
                  width: 300
                  height: 300
                  color: "blue"
                  Layout.fillWidth: true
                  Layout.fillHeight: true
              }        Rectangle {
                  width: 300
                  height: 300
                  color: "pink"
                  Layout.fillWidth: true
                  Layout.fillHeight: true
              }
          }    Text {
              text: "currentIndex: " + sl.currentIndex
          }    Row {
              anchors {
                  top: parent.top
                  right: parent.right
              }        Button {
                  text: "<"
                  onClicked: {
                      sl.currentIndex--
                  }
              }        Button {
                  text: ">"
                  onClicked: {
                      sl.currentIndex++
                  }
              }
          }    Button {
              id: btn
              anchors {
                  bottom: parent.bottom
                  horizontalCenter: parent.horizontalCenter
              }
              onClicked: {
                  console.log("BEFORE -> currentIndex:", sl.currentIndex)
                  sl.children[sl.currentIndex].parent = null
                  console.log("AFTER -> currentIndex:", sl.currentIndex)
              }
          }
      }
      

      Attachments

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

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            furkanzmc Furkan Üzümcü
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes