大佬教程收集整理的这篇文章主要介绍了动画 QML 按钮组件,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick 2.0
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1
import QtGraphicalEffects 1.0
Window
{
visible: true
wIDth: 640
height: 480
title: qsTr("Hello World")
TT
{
MouseArea
{
anchors.fill: parent
onClicked:
{
parent.buttonpressed = true
}
}
}
}
TT.qml
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick 2.0
import QtQuick.Controls 1.4
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.1
import QtGraphicalEffects 1.0
Rectangle
{
ID:ll
height: 20; wIDth: 100
property bool buttonpressed: false
button
{
ID: redRect
BACkground: Rectangle
{
height: 20; wIDth: 100
color: "red"
border.wIDth: 2
}
anchors.fill: parent
states: State {
name: "pressed"; when: ll.buttonpressed
PropertyChanges { target: redRect; scale: 1.2 ; }
}
Transitions: Transition
{
numberAnimation { propertIEs: "scale"; duration: 200; easing.type: Easing.InOutQuad }
}
}
}
我想通过 @H_350_15@main.qml 为按钮设置动画。
当我写 buttonpressed = true
时,问题是它始终保持正确。
我应该在哪里将它设置为 false 以便当我再次单击时它会再次动画?
@splaytreez 的回答有效,他建议删除您的 buttonPressed
财产和无关的 @H_317_5@mouseArea 是正确的。我想提供一个替代解决方案,因为我经常发现随着代码的增长和变得更加复杂,状态和转换很难遵循。更直接的方法是创建动画对象并直接调用它们。
Button {
id: redRect
onPressed: anim.start()
SequentialAnimation {
id: anim
// Expand the button
PropertyAnimation {
target: redRect
property: "scale"
to: 1.2
duration: 200
easing.type: Easing.InOutQuad
}
// Shrink BACk to normal
PropertyAnimation {
target: redRect
property: "scale"
to: 1.0
duration: 200
easing.type: Easing.InOutQuad
}
}
}
,
Transition
有一个属性 running
。你可以试试这样的:
transitions: Transition
{
numberAnimation {
properties: "scale";
duration: 200;
easing.type: Easing.InOutQuad
}
onRunningChanged: {
if (!running) buttonPressed = false;
}
}
现在,你真的需要这个属性吗?您是否考虑过使用 onPressed
信号:
Button {
// ...
onPressed: {
state = "pressed"
}
// ...
}
这样,无论何时按下按钮,状态都会改变(就像以前一样)并且您不需要使用 buttonPreessed
属性。
以上是大佬教程为你收集整理的动画 QML 按钮组件全部内容,希望文章能够帮你解决动画 QML 按钮组件所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。