Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. QML Button & ListModel
Forum Updated to NodeBB v4.3 + New Features

QML Button & ListModel

Scheduled Pinned Locked Moved Language Bindings
5 Posts 2 Posters 2.3k Views 2 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.
  • M Offline
    M Offline
    Marine93
    wrote on last edited by
    #1

    Good morning to all, this is my first post, I'm not sure I'm in the right category but ...
    I'm developing a program using a ListModel (and ListView) and I'm trying to establish a research function with this list. I have a Text Area where I can enter a name, and a button to search this name in the list. My function works but the problem is that it's not doing it in one go. To get my list sorted I have to push the button several times. Here is a part of my code :

    Rectangle {

        id: rectTextName
        width: 300
        height: 50
        anchors.centerIn: parent
        border.color: "black"
        visible: false
        
        TextEdit {
            
           id: zoneTextName
           anchors.fill: parent
           font.pointSize : 11
           text: "Entrer un nom"
    
           }
        
        Button {
            
            id: rechercher
            anchors.right: parent.right
            anchors.bottom: parent.bottom
            text: "Rechercher"
            onClicked: {
    
                    var i = 0
                    while (i<listejoueurs.model.count && listejoueurs.model.get(i).playerName!==zoneTextName.text){
                            listejoueurs.model.remove(i,1)
                             i++
                    }
                    
                    if (i<listejoueurs.model.count) {
                        i++
                    }
                    
                    while (i<listejoueurs.model.count) {
                            listejoueurs.model.remove(i,1)
                            i++
                    }
    
             }
    
        }
    
    }
    

    How to modify it so that when I push the button once, I get directly the sorted list?
    I don't know if I was clear enough, not easy for me as beside being a beginner in QT/QML, I'm french ;)

    Thanks for you answers.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Marine93
      wrote on last edited by
      #2

      I forgot to precise that when I say it doesn't do it in one go, I mean that the items to be eliminated are eliminated bit by bit, as and when I push the button again and again, and not all at the same time.

      p3c0P 1 Reply Last reply
      0
      • M Marine93

        I forgot to precise that when I say it doesn't do it in one go, I mean that the items to be eliminated are eliminated bit by bit, as and when I push the button again and again, and not all at the same time.

        p3c0P Offline
        p3c0P Offline
        p3c0
        Moderators
        wrote on last edited by
        #3

        @Marine93 Are you trying to sort the ListModel ?

        157

        M 1 Reply Last reply
        0
        • p3c0P p3c0

          @Marine93 Are you trying to sort the ListModel ?

          M Offline
          M Offline
          Marine93
          wrote on last edited by
          #4

          @p3c0 Not really, I'm trying to do a research in the list according to some criterias and I only want to keep the items of the list that respect these criterias

          p3c0P 1 Reply Last reply
          0
          • M Marine93

            @p3c0 Not really, I'm trying to do a research in the list according to some criterias and I only want to keep the items of the list that respect these criterias

            p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #5

            @Marine93 Well then you need a SortFilterProxyModel. It is based upon C++ QSortFilterProxyModel class. About the working you can find in this blog post. It shows for TableView but it will work for ListView too. Basically it will for those views which uses ListModel. You can find examples in Qt installed directory on your system too under quick directory.

            157

            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