qml - 在 QML 中的信号处理程序中使用转换属性时,“预期的标记 ','”
问题描述
我想Rectangle
在鼠标悬停的情况下为 a 进行转换。我按照本教程创建了一个MouseArea
这样的:
MouseArea{
anchors.fill: parent
hoverEnabled: true
onEntered: {
rMT.color = 'red' // rMT is my rectangle's id (rectangle_mouse_tracking)
transitions: Transition { // Expected token ','
NumberAnimation {
property : "width"
easing.type: Easing.InOutQuad
duration : 200
}
}
}
...
...
*还有其他可能的方法来制作动画,但我想知道上面的代码有什么问题?
目前我是 QML 的菜鸟。如果这个问题有点傻,很抱歉。
谢谢。
解决方案
当属性改变时,在转换中定义的动画被执行。
如果您希望在width
更改时执行动画,请更改 onEntered 中的宽度并执行 Rectangle 中定义的过渡。
语法错误是因为transitions
必须在 Rectange{} 而不是 onEntered {}
import QtQuick 2.14
import QtQuick.Window 2.14
import QtQuick 2.0
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Rectangle {
id: rMT
width: 400
height:400
x:0
color: 'blue'
border.color: 'black'
MouseArea{
anchors.fill: parent
hoverEnabled: true
onEntered: {
rMT.color = 'red'
rMT.width = 100
}
}
transitions: Transition{
NumberAnimation {
property : "width"
from: 400
easing.type: Easing.InOutQuad
duration : 2000
}
}
}
}
推荐阅读
- javascript - NodeJS 和 MongoDB “无法发布 /”
- sql - SQL 2 行成 1
- windows - 使用容器填充卷在 Windows 上的 Docker 中不起作用
- discord.js - TypeError:message.member.roles.some 不是函数
- python - psycopg2.errors.InvalidTextRepresentation
- node.js - 完成查询后正确关闭连接
- javascript - 如何使用 document.querySelectorAll jscript 自动单击按钮
- mysql - spring boot中的通信链路故障错误
- swift - 关闭窗口然后选择另一个应用程序时Mac应用程序消失
- javascript - Lodash 如何使用双键将 _.grouby 一组数据和 _.chain() 加倍?