我想向itemDelegate.onClick
添加另一个命令。
这是我的代码:
ListView {
id: beam_viewer
x: 8
y: 18
width: 188
height: 374
delegate: ItemDelegate {
id: delegate_item
width: 180
height: 25
Text {
text: modelData
anchors.verticalCenter: parent.verticalCenter
}
onClicked: img_footprint.source = applicationPath +
"footprints/" + modelData + ".webp"
}
}
我使用onClicked
来更改我的图片源,我想将modelData
用于myText.text。我使用ui.qml并且在onClicked之后它不允许使用{}因为它拒绝使用javascript
。
如何添加onClicked myText.text = modelData
。
谢谢!
答案 0 :(得分:0)
您可能需要将使用JavaScript的代码(例如包含ItemDelegate
项和其他内容的Text
的内容)移动到Qt Quick Designer可以使用的自己的.QML文件中。看。例如:
<强> MainForm.ui.qml 强>:
ListView {
id: beam_viewer
x: 8
y: 18
width: 188
height: 374
delegate: MyDelegate {}
}
<强> MyDelegate.qml 强>:
ItemDelegate {
id: delegate_item
width: 180
height: 25
Text {
text: modelData
anchors.verticalCenter: parent.verticalCenter
}
onClicked: img_footprint.source = applicationPath +
"footprints/" + modelData + ".webp"
}
就我个人而言,我不会使用ui.qml
个文件。我知道这不是一个非常令人满意的答案,但它似乎只会让我失望。