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. Can't set ListView.currentIndex
Forum Updated to NodeBB v4.3 + New Features

Can't set ListView.currentIndex

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 2.5k 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.
  • K Offline
    K Offline
    keolsen
    wrote on 27 Nov 2012, 19:52 last edited by
    #1

    Hi

    As the title says, I am not able to set currentIndex of the ListView...
    I have the ListView defined in one file and the model and delegate in seperate files.
    Everything seems to work fine except that I'm not able to set the currentIndex from the delegate.
    It's not unlikely I'm doing something totally wrong...I'm still not super sharp in this.
    Below is an example of what I'm trying to achieve...

    Thanks in advance.

    Example:

    myListView.qml

    @ListView {
    model: myModel
    delegate: myDelegate {}
    }
    @

    myDelegate.qml

    @Component {
    // something
    MouseArea {
    onClicked {
    ListView.currentIndex = index;
    }
    }
    }@

    1 Reply Last reply
    0
    • F Offline
      F Offline
      favoritas37
      wrote on 28 Nov 2012, 10:02 last edited by
      #2

      First of all the problem is at the line:
      @
      ListView.currentIndex = index;
      @

      You reference the property currentIndex through the type name of the component (ListView), not the id of the instance of the component as it should be.

      You can either try to just write the following and see what happens:
      @
      currentIndex = index;
      @

      Or in worst case scenario you can do something like the following:

      myListView.qml
      @
      ListView {
      model: myModel
      delegate: myDelegate {
      onClicked: currentIndex = index;
      }
      }
      @

      myDelegate.qml

      @
      Component {
      // something
      signal clicked(int index)

        MouseArea {
          onClicked {
              parent.clicked(index)
          }
        }
      }
      

      @

      1 Reply Last reply
      0

      1/2

      27 Nov 2012, 19:52

      • Login

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