Qt 如何在按下并释放时更改qml按钮的背景图像
我需要更改按钮按下时的背景图像。 如果按下按钮之前按钮上有背景图像,我需要在按下按钮时更改该背景图像,然后在松开按钮时将其设置回原始背景图像 这是我目前的代码:Qt 如何在按下并释放时更改qml按钮的背景图像,qt,qml,qtquick2,qt5.4,Qt,Qml,Qtquick2,Qt5.4,我需要更改按钮按下时的背景图像。 如果按下按钮之前按钮上有背景图像,我需要在按下按钮时更改该背景图像,然后在松开按钮时将其设置回原始背景图像 这是我目前的代码: property bool bImgChange: true Button { id: bu x: 121 y: 40 iconSource: "q.png" activeFocusOnPress: false opacity: 1 checkable: true che
property bool bImgChange: true
Button {
id: bu
x: 121
y: 40
iconSource: "q.png"
activeFocusOnPress: false
opacity: 1
checkable: true
checked: true
Layout.minimumWidth: 100
Layout.minimumHeight: 100
onClicked: {
if ( bImgChange == true )
{
bu.iconSource = "index.png"
bImgChange = false
}
else
{
bu.iconSource = "q.png"
bImgChange = true
}
}
}
上面的代码仅在单击按钮时设置背景图像,而我需要在按下和释放按钮时更改背景图像。按钮有一个按下的属性,可以这样使用:
Item {
Image { source: btn.pressed? "image1.png" : "image2.png"; ...}
Button { id: btn; ... }
}
Button {
iconSource: pressed? "image1.png" : "image2.png"
}
或者,如果要更改按钮的iconSource,可以尝试以下操作:
Item {
Image { source: btn.pressed? "image1.png" : "image2.png"; ...}
Button { id: btn; ... }
}
Button {
iconSource: pressed? "image1.png" : "image2.png"
}
希望有帮助。按钮有一个按下的属性,可以这样使用:
Item {
Image { source: btn.pressed? "image1.png" : "image2.png"; ...}
Button { id: btn; ... }
}
Button {
iconSource: pressed? "image1.png" : "image2.png"
}
或者,如果要更改按钮的iconSource,可以尝试以下操作:
Item {
Image { source: btn.pressed? "image1.png" : "image2.png"; ...}
Button { id: btn; ... }
}
Button {
iconSource: pressed? "image1.png" : "image2.png"
}
希望有帮助。谢谢,伙计,这真的帮了我的忙,我没有足够的声誉来提高分数。这是行不通的,你需要把它放在一个事件中。我想是的,你需要把它放在一个按钮上。这真的帮了我的忙,我没有足够的声誉来提高分数。这是行不通的,你需要把它放在一个事件中我想是的,你需要把它放在按钮按下的事件中