QT新手日记033

QT新手日记033

QTQUICK - MouseArea

import QtQuick

window

{

width:640

height:480

visible:true

title:qsTr("Rectangle使用")

Rectangle

{

id:标识号

width:100

height:100

color:"red"

anchors.bottom:parent.bottom对齐位置

border.color:"black"

border.width:1

MouseArea{

id:标识号

width:100

height:100

x:10

y:10

//上面的配置如果有下面这行的话则没有用了。

anchors.fill:parent//彼填充父层区域

hoverEnabled:true/false//鼠标进入时也会发信号,默认不会。

onClicked:(mouseover型的参数mouse)=>{

//单击要干点什么事

if(mouse.button==Qt.Leftbutton或者Qt.RightButton)

{

// 点左键或者右键不同的时候要处理什么业务?

}

}

onClicked:{

//单击要干点什么事

}

onDoubleClicked:{

//双击要干点什么事

}

onPressAndHold:{

//鼠标悬停时干点什么事

}

}

onEntered:{

//鼠标进入时做点什么事

}

onExited:{

//鼠标离开时做点什么事

}

onPositionChanged:(MouseEvent型的参数mouse)=>{

//鼠标位置发生变化时干点什么事?

//mouse.x和mouse.y决定了位置,当然还有mouse.button决定按下了什么键

}

onPressAndHold:(MouseEvent型的参数mouse)=>{

//鼠标持续按下超过800毫秒后干点什么事?

//mouse.x和mouse.y决定了位置,当然还有mouse.button决定按下了什么键

}

onPressed:(MouseEvent型的参数mouse)=>{

//鼠标按下干点什么事?

//mouse.x和mouse.y决定了位置,当然还有mouse.button决定按下了什么键

}

onReleased:(MouseEvent型的参数mouse)=>{

//鼠标放开时干点什么事?

//mouse.x和mouse.y决定了位置,当然还有mouse.button决定按下了什么键

}

onWheel:(WheelEvent的能数wheel)=>{

//当鼠标滚轮滚动时干点什么,一般wheel.angleDelta().y()表示正负120的滚动量,当然还有wheel.x(),wheel.y()表示位置

//wheel.button:int是通过位运算的多个按键是否按下:Qt.LeftButton|Qt.RightButton|Qt.MiddleButton

//wheel.inverted:bool传递增量值是否已正负反转。

//wheel.modifiers:int类似于button,表示键盘同时按下什么键:Qt.NoModifier/ShiftModifier/ControlModifier/AltModifier/MetaModifier/KeypadModifier等的或运算得到数据

}

//只读属性mouseX,mouseY表示鼠标位置,containsMouse表示是否在响应鼠标的区域内部

acceptedButtons:Qt.LeftButton|Qt.RightButton//表示允许响应什么按键。其中,Qt.AllButtons表示所有键,默认是Qt.LeftButton

cursorShape:Qt.ArrowCursor//表示鼠标前头样式。很多。

//Qt.ArrowCursor、、默认

//Qt.UpArrowCursor

//Qt.CrossCursor

//Qt.WaitCursor//等待

/Qt.IBeamCursor

//Qt.SizeVerCursor

//Qt.SizeHorCursor

//Qt.SizeBDiagCursor

//Qt.SizeFDiagCursor

//Qt.SizeAllCursor

//Qt.BlankCursor

//Qt.SplitVCursor

//Qt.SplitHCursor

//Qt.PointingHandCursor//小手

//Qt.ForbiddenCursor

//Qt.WhatsThisCursor//带小问号

//Qt.BusyCursor//繁忙

//Qt.OpenHandCursor

//Qt.ClosedHandCursor

//Qt.DragCopyCursor

//Qt.DragMoveCursor

//Qt.DragLinkCursor

//拖动

drag.target:parent

drag.axis:"XAxis"

drag.minimumX:30

drag.maximumX:150

drag.filterChildren:true

}

}

本节是MouseArea不可视的鼠标打击区域的,其他为辅助

相关推荐
王九思2 小时前
Java 内存分析工具 MAT
java·开发语言·安全
superman超哥3 小时前
Serde 的零成本抽象设计:深入理解 Rust 序列化框架的哲学
开发语言·rust·开发工具·编程语言·rust序列化
夕除3 小时前
java--2
java·开发语言
星辰徐哥3 小时前
Rust函数与流程控制——构建逻辑清晰的系统级程序
开发语言·后端·rust
liliangcsdn3 小时前
如何使用lambda对python列表进行排序
开发语言·python
java 乐山4 小时前
c 写一个文本浏览器(1)
c语言·开发语言
windows_64 小时前
MISRA C:2025 规则逐条分析
c语言·开发语言
fie88894 小时前
基于MATLAB的可见光通信(VLC)系统仿真
开发语言·matlab
写代码的【黑咖啡】4 小时前
Python中的lxml:高效XML处理库
xml·开发语言·python