StateELement 中的缩放元素

发布于 2024-11-30 22:04:50 字数 684 浏览 0 评论 0原文

我可以在下面写几行并让它工作:

states: State {
name: "active"; when:myitem.activeFocus;
                                            PropertyChanges { target: myitem; z:1000; scale: 1.2 }
                                            }
                                            transitions: Transition {
                                            NumberAnimation { properties: scale; duration: 1000 }
}

但是在这些行中我无法给出缩放属性的具体来源!

我发现 Scale Element

transform: Scale { origin.x: 25; origin.y: 25; xScale: 3}

如何将其注入到上面的状态属性中,因为我想使用状态的“when”属性,

我希望缩放在该“when”条件下运行。

或者是否有其他方法可以在指定原点的条件下进行缩放?

谢谢你的任何想法。

I can write lines below and got it work:

states: State {
name: "active"; when:myitem.activeFocus;
                                            PropertyChanges { target: myitem; z:1000; scale: 1.2 }
                                            }
                                            transitions: Transition {
                                            NumberAnimation { properties: scale; duration: 1000 }
}

But in these lines i can not give specific origin to scale property!

I found Scale Element

transform: Scale { origin.x: 25; origin.y: 25; xScale: 3}

How can i inject this into state property above, because i want to use "when" property of state,

i want scaling to run on that "when" condition.

Or is there any other way to scale in a condition with specifying origins?

Thanks for any idea.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖阳 2024-12-07 22:04:50

您应该为 Scale 元素设置一个 id。然后您可以在“活动”状态下更改其属性。

这里是一个最小的工作示例:

import QtQuick 1.0

Item {
    height: 200; width: 500

    Rectangle {
        id: myitem

        height: 10; width: 100
        anchors.centerIn: parent
        color: "blue"

        transform: Scale { id: scaleTransform; origin.x: 25; origin.y: 25 }

        states: State {
            name: "active"; when: mouseArea.pressed
            PropertyChanges { target: scaleTransform; xScale: 3 }
        }
        transitions: Transition {
            NumberAnimation { property: "xScale"; duration: 1000 }
        }
    }

    MouseArea {
        id: mouseArea
        anchors.fill: parent
    }
}

没有状态的另一种可能性可能是:

import QtQuick 1.0

Item {
    height: 200; width: 500

    Rectangle {
        id: myitem

        height: 10; width: 100
        anchors.centerIn: parent
        color: "blue"

        transform: Scale {
            id: scaleTransform
            origin.x: 25; origin.y: 25
            xScale: mouseArea.pressed ? 3 : 1  // <-

            Behavior on xScale {  // for animation
                NumberAnimation { duration: 1000 }
            }
        }
    }

    MouseArea {
        id: mouseArea
        anchors.fill: parent
    }
}

按下鼠标时将 xScale 设置为 3,否则设置为 1(如果您不知道“三元运算”,请查看 此处)。

You should set an id for the Scale element. Then you can change its properties in the "active" state.

Here a minimal working example:

import QtQuick 1.0

Item {
    height: 200; width: 500

    Rectangle {
        id: myitem

        height: 10; width: 100
        anchors.centerIn: parent
        color: "blue"

        transform: Scale { id: scaleTransform; origin.x: 25; origin.y: 25 }

        states: State {
            name: "active"; when: mouseArea.pressed
            PropertyChanges { target: scaleTransform; xScale: 3 }
        }
        transitions: Transition {
            NumberAnimation { property: "xScale"; duration: 1000 }
        }
    }

    MouseArea {
        id: mouseArea
        anchors.fill: parent
    }
}

Another possibility without states could be:

import QtQuick 1.0

Item {
    height: 200; width: 500

    Rectangle {
        id: myitem

        height: 10; width: 100
        anchors.centerIn: parent
        color: "blue"

        transform: Scale {
            id: scaleTransform
            origin.x: 25; origin.y: 25
            xScale: mouseArea.pressed ? 3 : 1  // <-

            Behavior on xScale {  // for animation
                NumberAnimation { duration: 1000 }
            }
        }
    }

    MouseArea {
        id: mouseArea
        anchors.fill: parent
    }
}

xScale is set to 3 when mouse is pressed, else to 1 (if you don't know the " ternary operation" look here).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文