9

I need some help with adding elements into a qml listview, i have a textarea and a button that will add the textarea text into a listview item when is pressed, here's my attempt:

Component {
    id: delegate
    Item {
        width: 200; height: 28
        Label {
            text: score
        }
    }
}

ListView {
     id: p1scores
     model: p1model
     delegate: delegate
     anchors.top: p1name.bottom
     anchors.topMargin: units.gu(1)
}

ListModel {
     id: p1model
     ListElement { score: "0" }
}

TextArea {
     id: p1input
     width: units.gu(8)
     height: units.gu(3)
     horizontalAlignment: TextEdit.AlignHCenter
     inputMethodHints: Qt.ImhDigitsOnly
     contentHeight: units.gu(60)
     anchors.topMargin: units.gu(8)
}

Button {
     id:p1button
     text: i18n.tr("Add")
     width: units.gu(8)
     onClicked: {
        p1model.append({"score": p1input.text})
        p1input.text = ""
     }
}

i tried appending it but doesn't shows up in the listview... any help?

4
  • 4
    in your p1button onClicked, you cleared the text in TextArea before adding the text to the ListModel, of course the text wouldn't show up. Commented Jan 21, 2013 at 6:58
  • The text still doesn't shows up, i think its a problem with the delegate... (edited the question) Commented Jan 22, 2013 at 3:33
  • I'm not sure but... change your delegate Component id to something else, because when you use delegate: delegate in your ListView, it assume is delegate: p1scores.delegate, so it bind back to itself. Commented Jan 23, 2013 at 4:17
  • i found the problem, it was that i didn't specified a height to the listview and apparently the default is the size of a single item... Commented Jan 23, 2013 at 23:52

1 Answer 1

15

Try without quotes around 'score', like this:

onClicked: {
    p1model.append({score: p1input.text})
    p1input.text = ""
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.