简体   繁体   English

处理QML动画的屏幕分辨率更改

[英]Handling screen resolution changes for QML Animations

I am a creating a fully scalable application on QML, what I need to know is how do I handle screen changes, for example this elements animation works for 1920x1080: 我正在QML上创建一个完全可扩展的应用程序,我需要知道如何处理屏幕更改,例如,此元素动画适用于1920x1080:

EventLog{
        id: eventlog
        x: 0
        y: 1000
        z: 10
        NumberAnimation{id: showeventPanel; target: eventlog; properties: "y"; to: 710; duration: 500}
    }

But I cannot anchor this element otherwise the animation will not take place, so for other resolutions this element will not be correctly placed, I realise that I can set the the anchor to anchors: undefined but how can I accurately set the x and y to move too the correct position on the screen? 但我无法锚定此元素,否则动画将不会发生,因此对于其他分辨率,此元素将无法正确放置,我意识到可以将锚设置为锚:未定义,但如何准确地将x和y设置为在屏幕上移动的位置是否太正确?

The solution I found, though not elegant, works to a certain degree. 我发现的解决方案虽然不完善,但在一定程度上可行。 I anchored the element as so and set it to a dummy rect(centreRect) that I anchored to the correct x and y position: 我将元素原样锚定并将其设置为虚拟rect(centreRect),并将其锚定到正确的x和y位置:

CameraControlPanel{
        id: control_Panel
//        x: 1916
//        y: 270
        anchors {
            verticalCenter: parent.verticalCenter
            right: parent.right

        }
        anchors.rightMargin: -635

        NumberAnimation{id: showPanel; target: control_Panel; properties: "x"; to: centreRect.x; duration: 500}
        z: 10
    }

Then when I needed to start the 'showPanel' animation I set the the anchors to undefined as so: 然后,当我需要启动“ showPanel”动画时,将锚点设置为undefined,如下所示:

        control_Panel.anchors.verticalCenter = undefined
        control_Panel.anchors.right = undefined

When I needed to return the element to the correct position, I reset the anchors that were there previously. 当我需要将元素返回到正确的位置时,我重置了之前的锚点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM