Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. ListView currentIndex strange behaviour
Forum Updated to NodeBB v4.3 + New Features

ListView currentIndex strange behaviour

Scheduled Pinned Locked Moved QML and Qt Quick
listviewbinding
1 Posts 1 Posters 765 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    justmatt
    wrote on 20 Aug 2015, 18:59 last edited by justmatt
    #1

    Hello.
    This is very confusing for me, I don't know why this is working the way it is.
    Let me explain.
    I have ApplicationWindow which contains ListView. I want ListView to be the size of its parent.

    import QtQuick.Controls 1.3
    import QtQuick 2.4
    import QtQuick.Layouts 1.1
    import QtQml.Models 2.1
    
    ApplicationWindow {
        width: 800
        height: 600
        visible: true
        id: window
    
        property alias cwidth: window.width
    
        ListView {
            id: listView
            orientation: ListView.Horizontal
            snapMode: ListView.SnapOneItem
            boundsBehavior: Flickable.StopAtBounds
            highlightMoveDuration: 250
            currentIndex: 1
    
            height: parent.height
    
            // Case #1
            width: parent.width
    
            // Case #2
    //                width: window.width
    
            // Case #3
    //                anchors.fill: parent
    
            model: ObjectModel {
                Page {
                    width: listView.width
                    height: listView.height
                    color: "yellow"
                    text: "Page1"
                }
    
                Page {
                    width: listView.width
                    height: listView.height
                    color: "cyan"
                    text: "Page2"
                }
    
                Page {
                    width: listView.width
                    height: listView.height
                    color: "magenta"
                    text: "Page3"
                }
            }
        }
    }
    
    //Page is simply a Rectangle with a Text
    import QtQuick 2.4
    
    Rectangle {
        smooth: true
        antialiasing: true
    
        property alias text: nameText.text
    
        Text {
            id: nameText
            anchors.centerIn: parent
            text: "PAGE 1"
            font.pointSize: 24
        }
    }
    

    I set listView.currentIndex to 1 so the first thing I am supposed to see, after I launch the application is Page2 with cyan color.

    There are 3 cases.

    • parent.width
    • window.width
    • anchors.fill: parent OR window

    When I set listView.width to parent.width and launch application, I see Page1 instead of Page2 - Not good.
    When I set listView.width to window.width and launch application, I see Page2 - Good.
    When I set anchors.fill to parent and launch application, I see Page1 instead of Page2 - Not good.

    When I print listView.currentIndex property, it says it has value 1(in each case), exactly what I assigned to it.

    Do you have any idea why this happens? I would be very grateful if someone could explain it to me.

    1 Reply Last reply
    0

    1/1

    20 Aug 2015, 18:59

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved