QML(qt5):在调整大小的图像左上角的覆盖按钮
我有以下代码(减少到最少): 这将生成类似于以下内容的图像: 但是我想把按钮放在调整大小后的图像的左上角 完整图像位于:QML(qt5):在调整大小的图像左上角的覆盖按钮,qt,qml,qt5,qtquick2,Qt,Qml,Qt5,Qtquick2,我有以下代码(减少到最少): 这将生成类似于以下内容的图像: 但是我想把按钮放在调整大小后的图像的左上角 完整图像位于: 使用QML是否可以实现这一点?您需要访问缩放图像的实际大小,以便实现和 这将导致 Item { Image { id: img source: "cluster.png" width: 150 height: 150 fillMode: Image.PreserveAspectFit
使用QML是否可以实现这一点?您需要访问缩放图像的实际大小,以便实现和 这将导致
Item {
Image {
id: img
source: "cluster.png"
width: 150
height: 150
fillMode: Image.PreserveAspectFit
}
Button {
id: butn
anchors.left: img.left
anchors.top: img.top
anchors.leftMargin: (img.width - img.paintedWidth)/2
anchors.topMargin: (img.height - img.paintedHeight)/2
width: 20
height: 20
text: "Push!"
}
}
您可以选择使用
x
或y
而不是锚定和边距。您可以上传cluster.png吗?现在有点混乱。@Mitch好主意,我会调整大小(原来是5000x5000左右)并上传。
Item {
Image {
id: img
source: "cluster.png"
width: 150
height: 150
fillMode: Image.PreserveAspectFit
}
Button {
id: butn
anchors.left: img.left
anchors.top: img.top
anchors.leftMargin: (img.width - img.paintedWidth)/2
anchors.topMargin: (img.height - img.paintedHeight)/2
width: 20
height: 20
text: "Push!"
}
}