我想在QML中模仿Button,但为什么它只适用于containsMouse
和!containsMouse
,它不适用于OnPressed
。你能帮助我吗 ?谢谢。
Item {
id: area
property string str_noPressed;
property string str_hover;
property string str_pressed;
Image {
id: background
width: 75; height: 75
source: userArea.containsMouse ? str_hover : str_noPressed
MouseArea {
id: userArea
anchors.fill: parent
onClicked: {}
onPressed: background.source = str_pressed
hoverEnabled: true
}
}
}
答案 0 :(得分:2)
显然,在按下按钮时,它还包含鼠标。
我认为containsMouse
优先于onPressed
。尝试:
onContainsMouseChanged: {
if (containsMouse && !pressed) {
background.source = str_pressed
}
}