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. how to filter listmodel elements by text without deleting and remaking items?
Forum Updated to NodeBB v4.3 + New Features

how to filter listmodel elements by text without deleting and remaking items?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 505 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.
  • Q Offline
    Q Offline
    qAminzzz
    wrote on last edited by qAminzzz
    #1

    hi, i used below code to search in listview and search does work fine
    but problem is that i don't want to clear list model and make it again
    this made a big problem for me

    CODE:

    function searchInListModel(filter) // my function
                {   
                    rigt_lisModl.clear() // this is bad
                    
                    for(var i = 0; i < root.crtItems.get("chartItem").length; i++) // adding again all items by text
                    {                    
                        if(root.crtItems.get("chartItem")[i][0].toLocaleLowerCase().search(filter.toLocaleLowerCase()) >= 0) // filtering
                        {
                            rigt_lisModl.append( // add filtered item 
                                                {
                                                    topTxt: root.crtItems.get("chartItem")[i][0],
                                                    centerTxt: root.crtItems.get("chartItem")[i][1],
                                                    clickedBorder: 0
                                                })
                        }
                    }       
                }
                
                onTextChanged:
                {
                    searchInListModel(text)
                } 
    

    i'm grateful for any help

    1 Reply Last reply
    0
    • fcarneyF Offline
      fcarneyF Offline
      fcarney
      wrote on last edited by
      #2

      https://doc.qt.io/archives/qt-5.9/qtquick-tutorials-dynamicview-dynamicview4-example.html

      I kind of wish I saw this earlier when doing some of this work. I ended up using some C++ models to do this.

      C++ is a perfectly valid school of magic.

      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