Qt 固定项目组件中图像的大小
我想固定项目中图像的大小,并在其右侧有一个更高的矩形 这是我的组件的声明Qt 固定项目组件中图像的大小,qt,qml,Qt,Qml,我想固定项目中图像的大小,并在其右侧有一个更高的矩形 这是我的组件的声明 import QtQuick 2.9 import QtQuick.Controls 2.5 Item { id: button width: 100 height: 200 signal clicked Image { id: backgroundImage anchors.fill: parent source: (button
import QtQuick 2.9
import QtQuick.Controls 2.5
Item {
id: button
width: 100
height: 200
signal clicked
Image {
id: backgroundImage
anchors.fill: parent
source: (button.enabled ? "images/simulation.png" : "images/simulation.png")
width: 100
height: 100
}
Rectangle {
color: "#22add8"
anchors.left: backgroundImage.right
anchors.leftMargin: 10
width: 5
height: 200
}
//Mouse area to react on click events
MouseArea {
anchors.fill: button
onClicked: {
console.log("clicked")
button.clicked()
}
onPressed: {
console.log("pressed")
backgroundImage.source = "images/simulation.png" }
onReleased: {
console.log("released")
backgroundImage.source = (button.enabled ? "images/simulation.png" : "images/simulation.png")
}
}
}
图像始终采用项目的高度
如何确定图像的大小?罪魁祸首如下:
Image {
// ...
anchors.fill: parent // <-- THIS
// ...
}
这将绑定图像的区域以填充其父图像。删除该行,您将得到100x100的固定图像