Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt 动态更改QML元素的转换_Qt_Qml - Fatal编程技术网

Qt 动态更改QML元素的转换

Qt 动态更改QML元素的转换,qt,qml,Qt,Qml,我花了相当长的时间才弄清楚旋转QML对象时遇到的问题,所以我决定与大家分享 问题是: 如何动态更新QML元素的旋转(如图像)。我知道我可以设置,例如,使用变换设置旋转(在MapQuickItem示例中): 但是,如何动态更新角度(或变换的其他部分) 关键信息是transform实际上是一个转换列表 因此,上述问题的一个可能解决方案是这样一个函数(例如,改变旋转): 关键信息是transform实际上是一个转换列表 因此,上述问题的一个可能解决方案是这样一个函数(例如,改变旋转): 更简洁的方法是

我花了相当长的时间才弄清楚旋转QML对象时遇到的问题,所以我决定与大家分享

问题是: 如何动态更新QML元素的旋转(如图像)。我知道我可以设置,例如,使用变换设置旋转(在MapQuickItem示例中):


但是,如何动态更新角度(或变换的其他部分)

关键信息是
transform
实际上是一个转换列表

因此,上述问题的一个可能解决方案是这样一个函数(例如,改变旋转):


关键信息是
transform
实际上是一个转换列表

因此,上述问题的一个可能解决方案是这样一个函数(例如,改变旋转):


更简洁的方法是使用属性或别名:

MapQuickItem
{
    sourceItem: Image
    {
        id: image

        property alias rotationAngle: rotation.angle

        anchors.centerIn: parent
        source: "image.png"
        sourceSize.width:  Screen.devicePixelRatio * 256
        sourceSize.height: Screen.devicePixelRatio * 256
        transform: Rotation { 
            id: rotation
            origin { x: image.sourceSize.width/2; 
                     y: image.sourceSize.height/2; 
                     z: 0} 
            angle: 0
        }
    }
}
与:


更简洁的方法是使用属性或别名:

MapQuickItem
{
    sourceItem: Image
    {
        id: image

        property alias rotationAngle: rotation.angle

        anchors.centerIn: parent
        source: "image.png"
        sourceSize.width:  Screen.devicePixelRatio * 256
        sourceSize.height: Screen.devicePixelRatio * 256
        transform: Rotation { 
            id: rotation
            origin { x: image.sourceSize.width/2; 
                     y: image.sourceSize.height/2; 
                     z: 0} 
            angle: 0
        }
    }
}
与:

MapQuickItem
{
    sourceItem: Image
    {
        id: image

        property alias rotationAngle: rotation.angle

        anchors.centerIn: parent
        source: "image.png"
        sourceSize.width:  Screen.devicePixelRatio * 256
        sourceSize.height: Screen.devicePixelRatio * 256
        transform: Rotation { 
            id: rotation
            origin { x: image.sourceSize.width/2; 
                     y: image.sourceSize.height/2; 
                     z: 0} 
            angle: 0
        }
    }
}
function updatePositionAndRotation(angleDeg)
{
    image.rotationAngle = angleDeg
}