Storing data using Settings element in QML

你离开我真会死。 提交于 2019-12-25 08:59:33

问题


I have the following code (windowid in code below refers to the root element's id, Root element's width & height are same as device's width & height (i.e FullScreened)

 Image{
        id:tick1
        source: "../../pics/tick.png"
        width:0.0395*windowid.width
        height:0.041*windowid.height
        x: 0.4474*windowid.width 
        y:  99
        visible: false

        MouseArea{
            anchors.fill: parent
            onClicked: tick1.y = tick1.y + 20
        }

        Settings{
            property alias yValue: tick1.y
        }


    }

The above code saves the y value of the image & ensure that the new y value will be stored and retrieved even if the application restarted to be the new image's y value, The above code works perfectly but if image's y value were initialized dynamically like this: y: 0.506*windowid.height instead of y: 99 Settings element wont work.

It seems like when y value is dynamically used, Qt executes everything (including the Settings element) then it starts to calculate any dynamic values found specially if that value depends on something else which is also dynamic as well (i.e device screen, width & height varies from one device to another).

How this issue can be fixed using dynamic values with the Settings element ?

来源:https://stackoverflow.com/questions/30131705/storing-data-using-settings-element-in-qml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!