Search code examples
qtqmlqt-quick

QML: how to handle mouse over?


QML: how to handle mouse over event on MouseArea? Can any one provide simple example or say what is wrong with mine?

import QtQuick 1.1
Image {
    source: "quit.png"
    scale:  mouseArea.containsMouse ? 0.8 : 1.0
    smooth: quitMouse.containsMouse
    MouseArea {
        id: quitMouse
        anchors.fill: parent
        anchors.margins: -10
        onClicked: Qt.quit()
    }
}

Solution

  • import QtQuick 1.1
    Image {
       source: "quit.png"
       scale:  mouseArea.containsMouse ? 0.8 : 1.0
       smooth: mouseArea.containsMouse
       MouseArea {
           id: mouseArea
           anchors.fill: parent
           anchors.margins: -10
           hoverEnabled: true         //this line will enable mouseArea.containsMouse
           onClicked: Qt.quit()
       }
    }