首页 文章

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

提问于
浏览
1

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

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

我知道我可以编辑我的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 }
    }
}

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)}
      }
    

相关问题