Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

Forums

OverviewFelgo 3 Support (Qt 5) › SortFilterProxyModel remove duplicates

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #24266

    Patrik Dusek

    Hi all,

    is there a way to get the SortFilterProxy removing duplicate entries in the list?

    Thx,

    patrik

    #24267

    Patrik Dusek

    I found one approach just using sections. This works so far fine for having only one of a kind.

    Problem now is, that I want to display a other property of my model than the one I use for building the

    sections. Is there a way to access the other properties of a model within the section delegate?

     

                  section {
                    property: "order"
                    delegate: Item {
                        id: sectDelegate
                            AppText{
                                text: section //and here instead of the section something like: model.name  
                                }
                            }
                    }

     

    #24274

    Alex
    Felgo Team

    Hi Patrik,

    the sections of a QML list view only have a few attached properties that you can work with. I am not sure what your exact use-case is, but maybe this example can give you an idea what you could do. It uses the property used to build the section, in order to access data from the model again:

    import QtQuick 2.5
    import Felgo 3.0
    
    App {
      NavigationStack {
        Page {
          title: "Sections"
    
          AppListView {
            id: listview
            model: ListModel {
              id: animalsModel
              ListElement { name: "Ant"; size: "Tiny" }
              ListElement { name: "Flea"; size: "Tiny" }
              ListElement { name: "Parrot"; size: "Small" }
              ListElement { name: "Guinea pig"; size: "Small" }
              ListElement { name: "Rat"; size: "Small" }
              ListElement { name: "Butterfly"; size: "Small" }
              ListElement { name: "Dog"; size: "Medium" }
              ListElement { name: "Cat"; size: "Medium" }
              ListElement { name: "Pony"; size: "Medium" }
              ListElement { name: "Koala"; size: "Medium" }
              ListElement { name: "Horse"; size: "Large" }
              ListElement { name: "Tiger"; size: "Large" }
              ListElement { name: "Giraffe"; size: "Large" }
              ListElement { name: "Elephant"; size: "Huge" }
              ListElement { name: "Whale"; size: "Huge" }
            }
    
            delegate: Text { text: name; font.pixelSize: 18 }
    
            section.property: "size"
            section.criteria: ViewSection.FullString
            section.delegate: Component {
              id: sectionHeading
              Rectangle {
                width: listview.width
                height: childrenRect.height
                color: "lightsteelblue"
    
                Text {
                  text: section + " " + listview.countChildren(section)
                  font.bold: true
                  font.pixelSize: 20
                }
              }
            }
    
            function countChildren(search) {
              var count = 0;
              for(var i=0; i<animalsModel.count; i++) {
                if(animalsModel.get(i)["size"] === search) {
                  count++;
                }
              }
              return count;
            }
          }
        }
      }
    }
    

     

    I hope that may give you an idea. In general, such sections are not closely related to the model or single entries of it, they are only aware of the property used to build the sections pretty much.

    Best,
    Alex

    #24276

    Patrik Dusek

    Hi Alex,

    as always: many thx 🙂

    The trick with the function searching by section works perfect for me.

    Thx,

    Patrik

Viewing 4 posts - 1 through 4 (of 4 total)

RSS feed for this thread

You must be logged in to reply to this topic.

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded