1

I want to know how to display a list if it contains a character. Example:

ListModel {
    id: fruitModel
    ListElement {
        name: "Apple"
        cost: 2.45
    }
    ListElement {
        name: "Orange"
        cost: 3.25
    }
    ListElement {
        name: "Banana"
        cost: 2.45
    }
}
UbuntuListView {
    objectName: "ubuntuListView"
    width: parent.width
    height: main.height
    model: fruitModel  
    spacing: units.gu(1)
    interactive: false
    delegate: ListItem.Subtitled {
        showDivider: true
        anchors.leftMargin: units.gu(2)
        Text {
            text: name
            color: openFoodFacts.settings.color
        }
        Label {
            anchors { right: parent.right; verticalCenter: parent.verticalCenter}
            anchors.rightMargin: 15;
            text: cost
        }
    }
} 

How to display only the fruit that costs 2.45 ?

Thank you for your help.

Sorry for my english, i'm french.

1 Answer 1

2

Supposed you're using the Ubuntu UI Toolkit (in your example you've declared an UbuntuListView), you can use a SortFilterModel.

SortFilterModel {
    id: sortedFruitModel
    model: fruitModel

    filter.property: "cost"
    filter.pattern: /2.45/
}

Then, in your ListView set "sortedFruitModel" as model.

0

Not the answer you're looking for? Browse other questions tagged .