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: disable auto selection
Forum Updated to NodeBB v4.3 + New Features

ListView: disable auto selection

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 915 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.
  • M Offline
    M Offline
    mIcHyAmRaNe
    wrote on last edited by
    #1

    Hello,
    i'm facing a small problem with ListView which is the item auto selection at the start.

    i created a search bar and when i search for something, it will append items to the listview, it works well but it auto select the first item of the list and i dont want that.
    i want that it select only when i click on a specific item

    so is there a way to do that?

    here is a part of my code:

    ListModel {
        id: lm    
    }
    Rectangle {
        width: drawer.width; height: drawer.height
        Component {
            id: contactDelegate
            Item {
                width: drawer.width; height: 100
                Row {
                    Image { width: 80; height: 100; source: posterSource}
                    Text { text: '<b>Title:</b> ' + title }
                }
                MouseArea {
                    anchors.fill: parent
                    onClicked: lv.currentIndex = index
                }
            }
        }
        ListView {
            id: lv
            anchors.fill: parent
            model: lm
            delegate: contactDelegate
            highlight: Rectangle { color: "#2196f3"; }
            focus: true
            onCurrentItemChanged: console.log(lm.get(lv.currentIndex).title + ' selected')
        }
    }
    

    Thank you

    KroMignonK 1 Reply Last reply
    0
    • M mIcHyAmRaNe

      Hello,
      i'm facing a small problem with ListView which is the item auto selection at the start.

      i created a search bar and when i search for something, it will append items to the listview, it works well but it auto select the first item of the list and i dont want that.
      i want that it select only when i click on a specific item

      so is there a way to do that?

      here is a part of my code:

      ListModel {
          id: lm    
      }
      Rectangle {
          width: drawer.width; height: drawer.height
          Component {
              id: contactDelegate
              Item {
                  width: drawer.width; height: 100
                  Row {
                      Image { width: 80; height: 100; source: posterSource}
                      Text { text: '<b>Title:</b> ' + title }
                  }
                  MouseArea {
                      anchors.fill: parent
                      onClicked: lv.currentIndex = index
                  }
              }
          }
          ListView {
              id: lv
              anchors.fill: parent
              model: lm
              delegate: contactDelegate
              highlight: Rectangle { color: "#2196f3"; }
              focus: true
              onCurrentItemChanged: console.log(lm.get(lv.currentIndex).title + ' selected')
          }
      }
      

      Thank you

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by KroMignon
      #2

      @mIcHyAmRaNe Have you tried to set currentIndex to -1?

          ListView {
              id: lv
              anchors.fill: parent
              currentIndex:-1
              model: lm
              delegate: contactDelegate
              highlight: Rectangle { color: "#2196f3"; }
              focus: true
              onCurrentItemChanged: console.log(lm.get(lv.currentIndex).title + ' selected')
          }
      

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      M 1 Reply Last reply
      2
      • M Offline
        M Offline
        mIcHyAmRaNe
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • KroMignonK KroMignon

          @mIcHyAmRaNe Have you tried to set currentIndex to -1?

              ListView {
                  id: lv
                  anchors.fill: parent
                  currentIndex:-1
                  model: lm
                  delegate: contactDelegate
                  highlight: Rectangle { color: "#2196f3"; }
                  focus: true
                  onCurrentItemChanged: console.log(lm.get(lv.currentIndex).title + ' selected')
              }
          
          M Offline
          M Offline
          mIcHyAmRaNe
          wrote on last edited by
          #4

          @KroMignon Thank you, it works

          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