17

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()
    }
}

1 Answer 1

25
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()
   }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.