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. [Solved] Select an item in an interactive ListView
Forum Update on Monday, May 27th 2025

[Solved] Select an item in an interactive ListView

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 12.4k Views
  • 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.
  • E Offline
    E Offline
    ephe
    wrote on last edited by
    #1

    Is it possible to select an item with a mouse click in an interactive ListView?

    As soon as I set interactive: true, I cannot select any elements in the ListView. Do I have to set another property?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      srikanth_trulyit
      wrote on last edited by
      #2

      setting interactive true enables to interact with the flickable area of the listview. Can you be more clear on what you mean by selecting an item? If you just need to highlight a selected item use highlight property.

      1 Reply Last reply
      0
      • E Offline
        E Offline
        ephe
        wrote on last edited by
        #3

        Sorry that my question was not that precise.

        I have set the highlight and I can also see it.
        When I press the keyboard up / down arrows, the highlight moves from one item to the other.
        But when I click on an item, the highlight is not moved to the clicked item.

        E.g. if I've got that list, the one with the --- is the highlighted one.
        Item1
        ---Item2---
        Item3
        Item4

        I press down:
        Item1
        Item2
        ---Item3---
        Item4

        Now I press up:
        Item1
        ---Item2---
        Item3
        Item4

        Now I click on Item4:
        Item1
        ---Item2---
        Item3
        Item4

        The highlight still stays on Item2, even though I want Item4 to be highlighted, and I don't know why.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          srikanth_trulyit
          wrote on last edited by
          #4

          Try using "highlightfollowscurrentitem":http://doc.qt.nokia.com/4.7-snapshot/qml-listview.html#highlightFollowsCurrentItem-prop property of ListView.

          1 Reply Last reply
          0
          • E Offline
            E Offline
            ephe
            wrote on last edited by
            #5

            I have tried that, but it still does not work.

            This is what my ListView looks like:
            @
            ListView {
            id: listView
            focus: true
            width: 400; height: 250
            anchors.bottomMargin: 50
            anchors.fill: parent
            currentIndex: 1
            highlight: highlight
            model: myModel
            delegate: MultiDelegate {}
            boundsBehavior: Flickable.StopAtBounds
            clip: true
            highlightFollowsCurrentItem: true
            onCurrentIndexChanged: console.log("current index changed")
            onCurrentItemChanged: console.log("current item changed")
            ScrollBar
            {
            flickable: listView
            vertical: true
            }
            }
            @

            when I click on an item, there is no output "current index changed" or "current item changed"

            1 Reply Last reply
            0
            • E Offline
              E Offline
              ephe
              wrote on last edited by
              #6

              I found the solution to the problem.
              In my delegate, I have added a MouseArea.
              in the onClicked of this MouseArea I've added:
              @
              onClicked: listView.currentIndex = index
              @
              Now the ListView is doing everything I want. It is flickable, you can can go up and down with the keyboard and you can click an item with the mouse to highlight it.

              1 Reply Last reply
              2

              • Login

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