Qt 大规模的行为往往是行不通的

Qt 大规模的行为往往是行不通的,qt,qml,Qt,Qml,我想有一个应用程序,总是在新的图像加载时,它是通过从0大小缩放到默认大小显示。这种行为通常不起作用。在这张图片中,当鼠标进入图片时,我也使用动画进行反弹。有没有可能,这两个动画不爱自己,这就是为什么放大通常不起作用 我使用的是LinuxMint13,Qt5.3 以下是我的图像元素: Image { id: pic1 width: appWindow.height*0.4 height: appWindow.height*0.4 sm

我想有一个应用程序,总是在新的图像加载时,它是通过从0大小缩放到默认大小显示。这种行为通常不起作用。在这张图片中,当鼠标进入图片时,我也使用动画进行反弹。有没有可能,这两个动画不爱自己,这就是为什么放大通常不起作用

我使用的是LinuxMint13,Qt5.3

以下是我的图像元素:

Image {
        id: pic1
        width: appWindow.height*0.4
        height: appWindow.height*0.4
        smooth: { enabled = true
            pic1MouseArea.containsMouse
        }
        states: [ "mouseIn", "mouseOut" ]
        state: "mouseOut"

        transitions: [
            Transition {
                from: "*"
                to: "mouseIn"
                NumberAnimation {
                    target: pic1
                    properties: "scale"
                    from: 0.95
                    to: 1
                    duration: 400
                    easing.type: Easing.OutBounce
                }
            }
        ]
        scale: {
            status === Image.Ready ? 1 : 0
        }
        Behavior on scale {
            NumberAnimation{
                from: 0
                to: 1
                duration: 1000
                easing.type: Easing.OutBounce
            }
        }
        MouseArea{
            id: pic1MouseArea
            hoverEnabled: true
            anchors.fill: parent
            onContainsMouseChanged: {
                pic1.state = containsMouse ? "mouseIn" : "mouseOut"
            }
            onClicked: {    
                    MyScript.getRandomFile()   
            }
        }
    }
首先,读一下这个。
状态
属性必须定义为
列表
,而不是字符串数组。另外,
State
元素定义了当属性或属性集从默认配置更改时的一些状态。在您的示例中,状态没有定义任何内容。阅读更多关于类型的信息

最后,这里有一个小例子可以帮助您取得成功:

import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Window 2.2

Window {
    width: 600
    height: 400
    visible: true
    Image {
        id: img
        source: "https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"
        anchors.centerIn: parent
        opacity: 1
        state: "mouseOut"
        states: [
            State {
                name: "mouseIn"
                PropertyChanges { target: img; opacity: 0 }
            },
            State {
                name: "mouseOut"
                PropertyChanges { target: img; opacity: 1 }
            }
        ]
        transitions: Transition {
            PropertyAnimation {
                target: img
                property: "opacity"
                easing.type: Easing.InCirc
                duration: 1000
            }
        }

        MouseArea {
            anchors.fill: parent
            hoverEnabled: true
            onEntered: img.state = "mouseIn"
            onExited: img.state = "mouseOut"
        }
    }
}
当然,如果您确实需要此功能,可以使用
行为
替换
转换
,如下所示:

Behavior on opacity {
    PropertyAnimation {
        duration: 1000
        easing.type: Easing.InCirc
    }
}