代码之家  ›  专栏  ›  技术社区  ›  sazr

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

  •  1
  • sazr  · 技术社区  · 7 年前

    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 }
        }
    }
    
    1 回复  |  直到 7 年前
        1
  •  5
  •   Miftakhul Arzak    7 年前

    可以使用“变换”和“缩放”

    transform: Scale{ xScale: -1 }
    
        2
  •  3
  •   dtech    7 年前

    可以,只需将水平镜像变换矩阵设置为形状:

    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)}
      }
    
    推荐文章