2
  1. Well I am trying to make a list of items having two texts and a checkbox in a listView.
  2. I wanted to add the price of the item when the checkbox is checked.
  3. To accomplish this, I need to know the index of the item of a listView so that I could get its "price" and I could store the data.
  4. I am unable to get the current Index of a list through a checkbox, as it behaves as an individual entity.
  5. However, I could get the index if I put a mouse area, but I need to grab it by checkbox.

for reference:

Component {     // delegate
        id:_delegate

        Rectangle{
            width: 100
            height: 50
            color: "beige"
            border.color: "black"
            Text {
                id: _textid
                text: name
            }
            Text {
                id: _textid2
                anchors.top: _textid.bottom;anchors.topMargin: 5
                anchors.left: _textid.left
                text: price
            }
            CheckBox {
            id:_checkbox
            anchors.top:parent.top;anchors.topMargin: 5
            anchors.left: parent.left;anchors.leftMargin: 50
            }
    }

1 Answers1

0

You can use the onCheckedChanged event and then get the price of the current index from your model, like this:

Component {     // delegate
        id:_delegate

        Rectangle{
            width: 100
            height: 50
            color: "beige"
            border.color: "black"
            Text {
                id: _textid
                text: name
            }
            Text {
                id: _textid2
                anchors.top: _textid.bottom;anchors.topMargin: 5
                anchors.left: _textid.left
                text: price
            }
            CheckBox {
                id:_checkbox
                anchors.top:parent.top;anchors.topMargin: 5
                anchors.left: parent.left;anchors.leftMargin: 50

                onCheckedChanged: {
                    _textid2.text = _checkbox.checked ? your_model.get(index).price : ""
                }
            }
    }
Adriano Campos
  • 1,121
  • 7
  • 14