【问题标题】:QML rotating a Gauge needle - pivot correctlyQML 旋转量规针 - 正确旋转
【发布时间】:2019-10-22 15:45:09
【问题描述】:

我正在尝试旋转 Gauge 针,但不是在针的底部旋转,针的底部有一个带十字的圆圈。针是围绕针尖旋转的。请参阅附图。图像是固定的/旋转的,但底座是旋转的。请建议如何纠正这个问题?

main.qml :--

import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 2.5

Window
{
    visible: true
    x :0
    y :0
    width: 800
    height: 480
    color: "grey"

    Rectangle
    {
        id: cluster
        Speed_Needle{
          id: cluster_pointer_base
          x : 214+16
          y : 222
        }
     }

    Slider
    {
        id  : slide_1
        width: parent.width
        from: 0
        to: 360
        value: 0
        enabled: true
        onValueChanged:
        {
            cluster_pointer_base.value=slide_1.value
        }
    }

}

Speed_Needle.qml :--

import QtQuick 2.0

Item {

    property int value: 0
    width: 186
    height: 36

    Image
    {
        id: root
        source: "files/pointer_needle2.png"
        x : 0
        y : 0
        transform: Rotation  {
            id: needleRotation
            angle : value

            Behavior on angle  {

                SmoothedAnimation { velocity: 50 }
            }
        }



    }

}

【问题讨论】:

    标签: qt qml


    【解决方案1】:

    你必须设置Rotationorigin

    Speed_Needle.qml :--

    import QtQuick 2.0
    
    Item {
    
        property int value: 0
        width: 186
        height: 36
    
        Image
        {
            id: root
            source: "files/REE Demo images/pointer_needle2.png"
            x : 0
            y : 0
            transform: Rotation  {
                id: needleRotation
                angle : value
                origin.x: root.width / 2    // here!
                origin.y: root.height / 2
    
                Behavior on angle  {
    
                    SmoothedAnimation { velocity: 50 }
                }
            }
        }
    }
    

    【讨论】:

    • 它工作了.. 我必须根据我的图像调整 origin.x
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-29
    • 2019-02-28
    • 1970-01-01
    相关资源
    最近更新 更多