Image 在裁剪为矩形时缩放QML中的图像';s码
我有一个固定大小的黄色QML矩形,我正在缩放其中的一个图像 当这种情况发生时,我的图像最终会变得比我的黄色矩形更大(显然)。但是当这种情况发生时,我希望我的图像只绘制在矩形内部,而不是延伸到它上面 这是我的代码:Image 在裁剪为矩形时缩放QML中的图像';s码,image,qml,qt5,scaletransform,Image,Qml,Qt5,Scaletransform,我有一个固定大小的黄色QML矩形,我正在缩放其中的一个图像 当这种情况发生时,我的图像最终会变得比我的黄色矩形更大(显然)。但是当这种情况发生时,我希望我的图像只绘制在矩形内部,而不是延伸到它上面 这是我的代码: import QtQuick 2.1 import QtQuick.Controls 1.0 Rectangle{ width: 1500 height: 1100 color: "red" Rectangle {
import QtQuick 2.1
import QtQuick.Controls 1.0
Rectangle{
width: 1500
height: 1100
color: "red"
Rectangle {
width: 900
height: 500
color: "yellow"
Component.onCompleted: init()
Image {
id: imagenCentro
width: 800
height: 400
fillMode: Image.PreserveAspectCrop
source: "http://www.bizh2o.com/wp-content/uploads/2015/02/shopping.jpg"
smooth: true
z: parent.z+1
opacity: 0.7
}
NumberAnimation {
id: animacion
target: imagenCentro
property: "scale"
to: 1.5
easing.type: Easing.InOutQuad
}
function init(){
imagenCentro.scale = 1
animacion.duration = 5000
animacion.start()
}
}
}
谢谢。在黄色矩形上设置为true
:
import QtQuick 2.1
import QtQuick.Controls 1.0
Rectangle {
width: 1500
height: 1100
color: "red"
Rectangle {
width: 900
height: 500
color: "yellow"
clip: true
Component.onCompleted: init()
Image {
id: imagenCentro
width: 800
height: 400
fillMode: Image.PreserveAspectCrop
source: "http://www.bizh2o.com/wp-content/uploads/2015/02/shopping.jpg"
smooth: true
z: parent.z + 1
opacity: 0.7
}
NumberAnimation {
id: animacion
target: imagenCentro
property: "scale"
to: 1.5
easing.type: Easing.InOutQuad
}
function init() {
imagenCentro.scale = 1
animacion.duration = 5000
animacion.start()
}
}
}
请注意,剪辑
:
默认情况下,剪裁处于禁用状态,仅应在需要时启用
剪辑是一种视觉效果,而不是优化。它增加(而不是降低)渲染器的复杂性。如果启用了“剪裁”,则项目会将其自己的绘画以及其子项的绘画剪裁到其边界矩形。这会阻止渲染器自由地重新排列元素的绘图顺序,从而导致次优的最佳场景图遍历
在委托中剪切尤其糟糕,应该不惜一切代价避免