Qt学习历程(二):QML鼠标悬停事件 光标进入退出某区域(非点击按压信号)

import QtQuick 2.5
import QtQuick.Window 2.2
Window {
    width: 200
    height: 150
    Rectangle {
        id: rect1
        x: 12; y: 12
        width: 76; height: 96
        color: "lightsteelblue"
        MouseArea {
            id: area
            width: parent.width
            height: parent.height
            anchors.fill: parent 
            hoverEnabled: true //默认是false
            onEntered: rect2.visible = !rect2.visible
            onExited: rect2.visible = !rect2.visible
            }
        }
    Rectangle {
        id: rect2
        x: 112; y: 12
        width: 76; height: 96
        border.color: "lightsteelblue"
        border.width: 4
        radius: 8
        }
}

你可能感兴趣的:(Qt,QML学习历程)