对 flip/reflect QML 控件应用镜像转换
Applying a mirror transformation to flip/reflect a QML Control
我可以水平 flip/reflect QML 中的形状项吗?例如;我有以下形状:
我可以flip/reflect横向生产吗:
我知道我可以编辑我的 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 }
}
}
是的,你可以,只需将水平镜像变换矩阵设置为以下形状:
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)}
}
您可以使用变换和缩放
transform: Scale{ xScale: -1 }
我可以水平 flip/reflect QML 中的形状项吗?例如;我有以下形状:
我可以flip/reflect横向生产吗:
我知道我可以编辑我的 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 }
}
}
是的,你可以,只需将水平镜像变换矩阵设置为以下形状:
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)}
}
您可以使用变换和缩放
transform: Scale{ xScale: -1 }