QML鼠标区域控制

时间:2021-08-03 14:56:24

鼠标操作使用很多,下面给出一个示例:

 import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2 Rectangle{
id: root
width: 210
height: 100 Rectangle{
id: rect1
width: 100; height:100
color: "lightsteelblue"
MouseArea{
anchors.fill: parent onClicked: {
rect2.visible = !rect2.visible
console.log("visible: ", rect2.visible)
}
}
} Rectangle{
id: rect2
x:110; y:0
width: 100; height:100
color: "lightsteelblue"
border.color: "lightgreen"
border.width: 5
radius: 10
} }