9

要素をqmlリストビューに追加する際に助けが必要です。テキストエリアと、押されたときにテキストエリアのテキストをリストビュー項目に追加するボタンがあります。これが私の試みです:

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 = ""
     }
}

追加しようとしましたが、リストビューに表示されません...助けはありますか?

4

1 に答える 1

14

次のように、「スコア」を引用符なしで試してください。

onClicked: {
    p1model.append({score: p1input.text})
    p1input.text = ""
}
于 2013-09-20T14:48:53.177 に答える