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. set index of ListView from Delegate
Forum Updated to NodeBB v4.3 + New Features

set index of ListView from Delegate

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 241 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    I'm trying to make a list of items clickable. When an item is clicked, the index of the list should be updated. Here's what I've got so far:

    ActivityModel { // from c++
        id: activityModel
    }
    
    Component {
        id: activityDelegate
        Activitybar {
            id: activityElement
        }
    }
    
    ListView {
        id: activityView
        model: activityModel
        delegate: activityDelegate
    }
    
    // Activitybar.qml
    Rectangle {
        id: activityBar
        MouseArea {
            anchors.fill: parent
            onClicked: {
                // how can I set the list index here?
            }
        }
    }
    

    Do I need an explicit property to hold the index in my Delegate? And if so, what's the syntax for the assignment?

    Thanks...

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by
      #2

      @mzimmers said in set index of ListView from Delegate:

      activityBar

      activityBar is the delegate and there is an index for each delegate
      onClicked: {
      console.log( index )
      }

      mzimmersM 1 Reply Last reply
      1
      • JoeCFDJ JoeCFD

        @mzimmers said in set index of ListView from Delegate:

        activityBar

        activityBar is the delegate and there is an index for each delegate
        onClicked: {
        console.log( index )
        }

        mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by
        #3

        @JoeCFD thank you.

        MouseArea {
            anchors.fill: parent
            onClicked: {
            activityView.currentIndex = index
            }
        }
        
        1 Reply Last reply
        0

        • Login

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