【发布时间】:2021-09-13 10:51:02
【问题描述】:
我是 QML 的新手,我正在尝试突出显示鼠标悬停上的图像。我有一排电影图像,像这样:
这是我的图像编号 4 (tarzan) 的代码:
Rectangle{
id:rect4
width: parent.width/5-row.spacing/5
height:parent.height
color:'transparent'
Image{
id: tarzan
fillMode: Image.PreserveAspectFit
anchors.fill: parent
source:'qrc:tarzan.jpg'
MouseArea{
id:area
width:parent.width
height: parent.height
hoverEnabled: true
anchors.fill:parent
onClicked:tarzan.forceActiveFocus()
}
我尝试了不同的方法,但没有任何反应。有任何想法吗?帮助将不胜感激。
【问题讨论】:
-
我没有看到任何处理悬停状态的代码。也许看看
containsMouse属性和 MouseArea 的entered和exited信号 -
好的,但是为什么
onClicked不起作用? -
onClicked对活动的鼠标点击做出反应,它对我有用。 Image 的.forceActiveFocus()方法不会突出显示图像,因此您必须实现另一种突出显示该图像的方法 -
我试过
onClicked: console.log("Button clicked!"),也没有任何反应。 -
感谢您的回答。我使用输入和退出信号解决了它。在里面我使用了
tarzan.scale=1.2,它起作用了。当我用鼠标悬停在图像上时,图像会改变大小。