Ubuntu SDK:如何在 QML 中为图像实现“onClick”?

Zax*_*ter 1 qt qt-creator qml

我的页面有一个背景图像,我想在单击背景时实现某种页面刷新。但是,我没有在 QT quick 中找到图像元素的任何操作。

实现这一点的正确方法是什么?

koo*_*jah 6

您需要使用MouseArea来处理点击事件。

Image {
    source: "myimage.png"

    MouseArea {
        anchors.fill: parent
        onClicked: {
            // do what you want here
        }
    }
}
Run Code Online (Sandbox Code Playgroud)