代码之家  ›  专栏  ›  技术社区  ›  mohsen

qt quick应用程序中的qml Animatin在ColumLayout中不起作用

  •  0
  • mohsen  · 技术社区  · 5 年前

    我想在SplashScreen上设置文本动画,但它不起作用,但这个qml动画可以工作,但大规模的动画可以工作

    import QtQuick 2.15
    import QtQuick.Controls 2.15
    import QtQuick.Window 2.15
    import QtQuick.Layouts 1.15
    Page{
        id:splashPage
        Component.onCompleted: {
            txtAnimation.start();
        }
        ColumnLayout{
            id:clm
            anchors.fill: parent
            Image {
                id: icon
                source: "/images/icon.png"
                Layout.preferredHeight: 200
                Layout.preferredWidth: 200
                Layout.alignment: Qt.AlignHCenter
                Layout.topMargin: (clm.implicitHeight-icon.height)/2
            }
            Text{
                id:txt
                text: "Title under application icon" 
                Layout.alignment: Qt.AlignHCenter|Qt.AlignTop
            }
            Item {
                Layout.fillHeight: true
            }
        }
        SequentialAnimation{
            id:txtAnimation
            NumberAnimation {
                target: txt
                duration: 1000
                easing.type: Easing.OutElastic
                properties: "x"
                from: -1000
            }
            SequentialAnimation {
                loops: Animation.Infinite
                alwaysRunToEnd: true
                PauseAnimation{
                    duration: 600
                }
                PropertyAnimation {
                    target: txt
                    property: "scale"
                    to: 1.0
                    duration: 100
                }
                PropertyAnimation {
                    target: txt
                    property: "scale"
                    to: 0.85
                    duration: 400
                }
                PropertyAnimation {
                    target: txt
                    property: "scale"
                    to: 1
                    duration: 100
                }
            }
        }
    }
    

    当我将NumberName改为Lower时,它可以工作,但在ColumnLayout中,它没有x属性

            NumberAnimation {
                target: txt
                duration: 1000
                easing.type: Easing.OutElastic
                properties: "x"
                from: -1000
                to:25
            }
    

    我像下面这样修改了代码,但它不起作用

            Text{
                id:txt
                text: "Title"
                color: "#7f0000"
                Layout.alignment: Qt.AlignHCenter|Qt.AlignTop
                Behavior on x{
                    NumberAnimation {
                        duration: 1000
                        //                    easing.type: Easing.OutElastic
                    }
                }
            }
    
    0 回复  |  直到 5 年前
        1
  •  1
  •   JarMan    5 年前

    设置 to 属性,但如果没有它就无法工作,这表明在这种情况下它是必要的。因此,只需将其设置为一个值,以保持文本水平居中。为此,请尝试以下方法:

        to: (clm.width - txt.width) / 2