我想在一个项目中固定图像的大小,并在它的右边有一个更高的矩形。
下面是我的组件的声明
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")
}
}
}图像始终采用项目的高度
如何确定图片的大小?
发布于 2019-04-05 01:50:17
这就是罪魁祸首:
Image {
// ...
anchors.fill: parent // <-- THIS
// ...
}这将绑定图像的区域以填充其父图像。去掉这一行,你应该得到一个100x100的固定图像。
https://stackoverflow.com/questions/55519178
复制相似问题