Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML, dynamically adding elements to a listview

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?

like image 650
Hairo Avatar asked Jan 20 '13 23:01

Hairo


1 Answers

Try without quotes around 'score', like this:

onClicked: {
    p1model.append({score: p1input.text})
    p1input.text = ""
}
like image 134
Patrick Avatar answered Nov 01 '22 05:11

Patrick