Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
QML(qt5):在调整大小的图像左上角的覆盖按钮_Qt_Qml_Qt5_Qtquick2 - Fatal编程技术网

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!"
    }
}