应用镜像变换来翻转/反射 QML 控件 [英] Applying a mirror transformation to flip/reflect a QML Control
问题描述
我可以在 QML 中水平翻转/反射形状项目吗?例如;我有以下形状:
Can I horizontally flip/reflect a shape item in QML. For example; I have the below shape:
我可以水平翻转/反射它来产生吗:
Can I flip/reflect it horizontally to produce:
我知道我可以编辑我的 QML 代码以不同的方式绘制线条,但如果可能的话,只使用 QML 动画或其他东西来翻转它会更简单.
I know I could edit my QML code to draw the lines differently but it would be much simpler to just use a QML animation or something to flip it if thats possible.
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 }
}
}
推荐答案
可以,只需为形状设置一个水平镜像变换矩阵即可:
Yes you can, by simply setting a horizontal mirror transformation matrix to the shape:
transform: Matrix4x4 {
matrix: Qt.matrix4x4(-1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
}
x
的位置并没有真正改变,它仍然是一样的,只是对象现在被转换渲染了.您可以通过在矩阵顶部堆叠翻译来弥补这一点:
The x
position doesn't really change, it is still the same, it is just that the object is now rendered with the transformation. You can compensate for that by stacking a translate on top of the matrix:
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:
实际上,您可以将转换合并到原始矩阵中以简化一些事情:
Actually, you can incorporate the translation in the original matrix to simplify things a bit:
transform: Matrix4x4 {
matrix: Qt.matrix4x4( -1, 0, 0, but.width, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)}
}
这篇关于应用镜像变换来翻转/反射 QML 控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!