首页 文章

QML如何在mouseArea中设置颜色

提问于
浏览
1

我想设计以下按钮布局:

Link

它有一个重新启动按钮图像放在蓝色背景上 . 我想使用QML在Qt中复制相同的内容 . 我正在使用MouseArea Qt Quick对象,我在Stretch填充模式下重叠图像 . 但是,没有选项可以获得鼠标区域的蓝色背景 . 目前它看起来像这样:

Link

相应的代码相同:

MouseArea {
    id: restartbutton
    x: 669
    width: 50
    height: 50
    opacity: 1
    antialiasing: false
    hoverEnabled: true
    anchors.top: parent.top
    anchors.topMargin: 8
    z: 1

    Image {
        id: image2
        anchors.fill: parent
        source: "restart_icon.png"
    }

}

如何在此处设置MouseArea的背景?

1 回答

  • 1

    您可能想要像这样使用 Rectangle

    Rectangle {
      width:50
      height: 50
      Image {
        anchors.fill:parent
        source: "restart_icon.png"
      }
      MouseArea {
        anchors.fill:parent
        onClicked: {...}
      }
    }
    

    请查看QML Advanced Tutorial以获取更多信息

相关问题