Image 如何在组件外部设置图像源
我的QML应用程序中的对话框中显示了一个图像,我希望以后能够使用onClicked更改该图像,我通过一个函数传递该图像,以检查新源URL中所需的变量是否是我所需的变量之一 我只是尝试使用Image.source=“NEWURL”,这是不可能的。还有图像所在组件的id,以及类似于:id.source=“neurl”-no go的对话框 我该怎么做 编辑:添加更多代码;函数和listitm都用于单击。该图像是一个web图像,我希望在url中包含conncectedUser值(这是一个用户名) 以下是所有相关代码:Image 如何在组件外部设置图像源,image,qt,qml,Image,Qt,Qml,我的QML应用程序中的对话框中显示了一个图像,我希望以后能够使用onClicked更改该图像,我通过一个函数传递该图像,以检查新源URL中所需的变量是否是我所需的变量之一 我只是尝试使用Image.source=“NEWURL”,这是不可能的。还有图像所在组件的id,以及类似于:id.source=“neurl”-no go的对话框 我该怎么做 编辑:添加更多代码;函数和listitm都用于单击。该图像是一个web图像,我希望在url中包含conncectedUser值(这是一个用户名) 以下是
// Check if users is really a user, and if; show skin
function checkCurrentUser(currentUser) {
console.debug('Debug: Check user "'+currentUser+'" if actually a user.')
if (currentUser == "Ingen online") {
currentUser = "Notch" // reset currentUser if pushed earlier
console.debug('Debug: It was not a real user. Showing '+currentUser+' instead')
Image.source = "http://blabla"+currentUser+"yesyes"
}
else {
console.debug('Debug: It was a real user.')
Image.source = "http://blabla"+currentUser+"yesyes"
}
return "http://blabla"+currentUser+"yesyes""
}
// the dialog I want to show with a image
Component {
id: userDialog
Dialog {
id: dialogueUser
title: i18n.tr("Image")
Image {
id: usersSkin
fillMode: Image.PreserveAspectFit
source: "URL"
sourceSize.height: 1200
}
Button {
text: i18n.tr("Close")
color: "red"
onClicked: PopupUtils.close(dialogueUser)
}
}
}
// and then the list containting each link, which on click should show the user image
ListView {
id: userList
width: parent.width
height: units.gu(5)
model: msmData
delegate: ListItem.Standard {
text: connectedUser
onClicked: {
console.debug('Debug: User clicked "'+connectedUser+'"')
checkCurrentUser(connectedUser)
PopupUtils.open(userDialog, userList)
}
}
header: ListItem.Header { text: i18n.tr("Connected Users") }
section.property: "type"
section.criteria: ViewSection.FullString
section.delegate: ListItem.Header { text: i18n.tr(section) }
}
我不确定我是否正确理解了你的问题,但我会尝试一下:
Component
{
id: userDialog
Dialog
{
property int sourceState : 1
id: dialogueUser
title: i18n.tr("Image")
Image
{
id: usersSkin
fillMode: Image.PreserveAspectFit
source: 1 == sourceState ? "OLDURL" : "NEWURL"
sourceSize.height: 1200
}
Button
{
text: i18n.tr("Close")
color: "red"
onClicked:
{
PopupUtils.close(dialogueUser)
dialogueUser.sourceState = 0
}
}
}
}
我最后做的只是重置图像URL中的变量,然后显示对话框。现在开始工作。
我已经尝试使用Image.source=“NEWURL”这是一个不可行的方法
你能解释一下原因吗?嗨,阿米特,图像不会显示出来。谢谢,但是我需要根据用户点击推送一个变量到新的URL中,它来自一个委托的XML列表项。