QML映像缩放意外行为
Qt 5.9.2 以下QML代码:QML映像缩放意外行为,qml,Qml,Qt 5.9.2 以下QML代码: ApplicationWindow { visible: true width: 585 height: 113 title: qsTr("test") Rectangle { width: 585 height: 113 color: "black" x: 0 y: 0 } Image { s
ApplicationWindow
{
visible: true
width: 585
height: 113
title: qsTr("test")
Rectangle
{
width: 585
height: 113
color: "black"
x: 0
y: 0
}
Image
{
source: "balloon.png"
x: 0
y: 0
}
}
产生预期的结果:
当我将scale:0.5
添加到Image
元素时,我得到以下结果:
但我希望它是这样的:
有人能解释一下为什么0.5缩放图像不位于(0,0)坐标处,因为它在属性中明确设置,并且可以在此处执行某些操作以使缩放图像位于(0,0)坐标处吗?如中所述,缩放是从应用的,默认原点是项,因此,您需要指定项。左上角:
import QtQuick 2.7
import QtQuick.Controls 2.0
ApplicationWindow {
visible: true
width: 585
height: 113
title: qsTr("test")
Rectangle {
width: 585
height: 113
color: "black"
x: 0
y: 0
}
Image {
source: "balloon.png"
x: 0
y: 0
scale: 0.5
transformOrigin: Item.TopLeft
}
}
x
和y
属性仅影响项目的位置,而不影响其缩放原点。请注意,如果需要进行更高级的转换,也有该属性。在锚定到缩放的项时,也要小心,因为它不会缩放边界框。