Mousearea
属性:
acceptedButtons:
接受的鼠标按键,默认是左键
Qt.LeftButton | Qt.RightButton | Qt.AllButtons等等
pressedButtons:
按下的是什么键?左键or右键等
Rectangle{
color: "yellow"
anchors.centerIn: parent
width: 200
height: 200
MouseArea {
id: mouseArea
anchors.fill: parent
acceptedButtons: Qt.LeftButton | Qt.RightButton
onPressed: {
var ret =pressedButtons & Qt.RightButton
console.log(ret? "right":"left")
}
}
}
hoverEnabled :bool
是否开启触发光标悬浮的层
containsMouse : bool
光标是不是在这我的area里面
containsPress : bool
光标是不是在area里面按下
Rectangle{
color: "yellow"
anchors.centerIn: parent
width: 200
height: 200
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled:true
acceptedButtons: Qt.LeftButton | Qt.RightButton
onPressed: {
var ret =pressedButtons & Qt.RightButton
console.log(ret? "right":"left")
}
onContainsMouseChanged: {console.log("onContainsMouseChanged",containsMouse)}
onContainsPressChanged: {console.log("onContainsPressChanged",containsPress)}
}
}
cursorShape : Qt::CursorShape
光标的样式选择,进入area后会变样式
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled:false
cursorShape: Qt.SplitVCursor
acceptedButtons: Qt.LeftButton | Qt.RightButton
onPressed: {
var ret =pressedButtons & Qt.RightButton
console.log(ret? "right":"left")
}
onContainsMouseChanged: {console.log("onContainsMouseChanged",containsMouse)}
onContainsPressChanged: {console.log("onContainsPressChanged",containsPress)}
drag
拖动
-
drag.target : Item
指定控件 -
drag.active : bool
-
drag.axis : enumeration
指定轴 -
drag.minimumX : real
指定值 -
drag.maximumX : real
指定值 -
drag.minimumY : real
指定值 -
drag.maximumY : real
指定值 -
drag.filterChildren : bool
指定子控件是否继承拖动 -
drag.threshold : real
Rectangle {
id: container
width: 600; height: 200
Rectangle {
id: rect
width: 50; height: 50
color: "red"
opacity: (600.0 - rect.x) / 600
MouseArea {
anchors.fill: parent
drag.target: rect
drag.axis: Drag.XAxis|Drag.YAxis
drag.minimumX: 0
drag.maximumX: container.width - rect.width
}
}
}
enabled : bool
是否使能area
mouseX : real
光标在区域移动的坐标 需要hoverEnabled :bool
联动
mouseY : real
光标在区域移动的坐标 需要hoverEnabled :bool
联动
pressAndHoldInterval : int
长按触发信号的时间 单位ms
propagateComposedEvents : bool
子area是否可以触发父area的信号
信号函数:
clicked:
鼠标的点击
pressed:
按下鼠标
relesed:
松开鼠标
标签:real,console,Qt,log,MouseArea,drag,bool,qml,qt From: https://blog.csdn.net/weixin_60755571/article/details/137353013