应用镜像转换来翻转/反映QML控件

问题描述 投票:1回答:1

我可以在QML中水平翻转/反映形状项。例如;我有以下形状:

enter image description here

我可以水平翻转/反射产生:

enter image description here

我知道我可以编辑我的QML代码以不同的方式绘制线条,但如果可能的话,只使用QML动画或其他东西来翻转它会更简单。

Shape {
    id: annotationHLine;
    anchors.left: annotationShp.right;
    anchors.top: annotationShp.top;
    anchors.topMargin: annotationShp.height * 0.5;

    ShapePath {
        strokeWidth: 2;
        strokeColor: "Green";
        fillColor: "transparent";
        startX: -slant; startY: 0;
        PathLine { x: relativeTargetX*0.5; y: 0 }
        PathLine { x: relativeTargetX; y: relativeTargetY }
    }
}
qt qml qtquickcontrols2
1个回答
1
投票

是的,您可以通过简单地将水平镜像变换矩阵设置为形状:

transform: Matrix4x4 {
      matrix: Qt.matrix4x4(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
    }

编辑:

x位置并没有真正改变,它仍然是相同的,只是现在通过转换渲染对象。您可以通过在矩阵顶部堆叠平移来弥补这一点:

transform: [
  Matrix4x4 {
    matrix: Qt.matrix4x4(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
  },
  Translate {
    x: annotationHLine.width
  }
]

编辑2:

实际上,您可以将翻译合并到原始矩阵中以简化操作:

transform:  Matrix4x4 {
    matrix: Qt.matrix4x4( -1, 0, 0, but.width, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)}
  }
© www.soinside.com 2019 - 2024. All rights reserved.