修改 ListElement (QML) 内的工具提示文本
Modify ToolTip Text inside ListElement (QML)
我实际上是在用 Python 和 QML 开发一个软件。多亏了一些好的视频,我已经设法自学了它,但最近我遇到了一个我无法处理的问题。
这是我的 ListView 元素:
ListView {
id: listView
anchors.fill:parent
anchors.bottom: start_button.top
anchors.rightMargin: 10
anchors.leftMargin: 10
anchors.topMargin: 20
delegate: informationDelegate
model: ListModel { id:informationModel }
}
好吧,如您所见,我有一个委托来“预格式化”我的列表:
Component{
id:informationDelegate
Column {
spacing: 5
height: 60
Text { text: name ; font.bold: true ; color: "#ffffff" }
Text { text: path ; color: "#ffffff" ; ToolTip.delay: 1000 ; ToolTip.visible: ma.containsMouse ; ToolTip.text: qsTr("Tooltip empty")
MouseArea { id: ma ; anchors.fill: parent ; hoverEnabled: true}
}
}
}
然后,我想修改 JS 函数中的 Tooltip.text 值,但我找不到办法。我已经尝试了很多东西,但并没有找到真正的方法。
informationModel.clear()
informationModel.append ({"name" : "Ansible Playbook :" , "path.ToolTip.text" : obj.ansiblePath , "path" : obj.ansiblePath.split('/').pop() })
informationModel.append ({"name" : "Configuration File :" , "path.ToolTip.text" : qsTr(obj.ansiblePath) , "path" : displayConf.split('/').pop() })
informationModel.append ({"name" : "Firmware File :" , "path.ToolTip.text" : qsTr(obj.ansiblePath) , "path" : displayFirmware.split('/').pop() })
如果您对这个问题有任何提示,请告诉我 ;)
你的方法是错误的,模型没有直接修改视图,而是视图使用模型修改自己,所以你的情况你必须创建一个 属性 并与 [=12 进行绑定=]:
Component{
id:informationDelegate
Column{
required property string name
required property string path
required property string message
spacing: 5
height: 60
Text {
text: name
font.bold: true
color: "#ffffff"
}
Text {
text: path
ToolTip.delay: 1000
ToolTip.visible: ma.containsMouse
ToolTip.text: message
MouseArea {
id: ma
anchors.fill: parent
hoverEnabled: true
}
}
}
}
informationModel.clear()
informationModel.append({"name" : "Ansible Playbook :" , "message" :"message1" , "path" : "path1" })
informationModel.append({"name" : "Configuration File :" , "message" : "message2" , "path" : "path2" })
informationModel.append({"name" : "Firmware File :" , "message" : "message3" , "path" : "path3" })
我实际上是在用 Python 和 QML 开发一个软件。多亏了一些好的视频,我已经设法自学了它,但最近我遇到了一个我无法处理的问题。
这是我的 ListView 元素:
ListView {
id: listView
anchors.fill:parent
anchors.bottom: start_button.top
anchors.rightMargin: 10
anchors.leftMargin: 10
anchors.topMargin: 20
delegate: informationDelegate
model: ListModel { id:informationModel }
}
好吧,如您所见,我有一个委托来“预格式化”我的列表:
Component{
id:informationDelegate
Column {
spacing: 5
height: 60
Text { text: name ; font.bold: true ; color: "#ffffff" }
Text { text: path ; color: "#ffffff" ; ToolTip.delay: 1000 ; ToolTip.visible: ma.containsMouse ; ToolTip.text: qsTr("Tooltip empty")
MouseArea { id: ma ; anchors.fill: parent ; hoverEnabled: true}
}
}
}
然后,我想修改 JS 函数中的 Tooltip.text 值,但我找不到办法。我已经尝试了很多东西,但并没有找到真正的方法。
informationModel.clear()
informationModel.append ({"name" : "Ansible Playbook :" , "path.ToolTip.text" : obj.ansiblePath , "path" : obj.ansiblePath.split('/').pop() })
informationModel.append ({"name" : "Configuration File :" , "path.ToolTip.text" : qsTr(obj.ansiblePath) , "path" : displayConf.split('/').pop() })
informationModel.append ({"name" : "Firmware File :" , "path.ToolTip.text" : qsTr(obj.ansiblePath) , "path" : displayFirmware.split('/').pop() })
如果您对这个问题有任何提示,请告诉我 ;)
你的方法是错误的,模型没有直接修改视图,而是视图使用模型修改自己,所以你的情况你必须创建一个 属性 并与 [=12 进行绑定=]:
Component{
id:informationDelegate
Column{
required property string name
required property string path
required property string message
spacing: 5
height: 60
Text {
text: name
font.bold: true
color: "#ffffff"
}
Text {
text: path
ToolTip.delay: 1000
ToolTip.visible: ma.containsMouse
ToolTip.text: message
MouseArea {
id: ma
anchors.fill: parent
hoverEnabled: true
}
}
}
}
informationModel.clear()
informationModel.append({"name" : "Ansible Playbook :" , "message" :"message1" , "path" : "path1" })
informationModel.append({"name" : "Configuration File :" , "message" : "message2" , "path" : "path2" })
informationModel.append({"name" : "Firmware File :" , "message" : "message3" , "path" : "path3" })