QLabel中鼠标常用事件
enterEvent 鼠标进入事件
鼠标进入离开事件 是虚函数
可以重写
QLabel Reimplemented Punctions
重新实现的方法
virtul void mouseMoveEvent
自己写一个QLabel
右键 添加新文件 C++ Class
所有控件 QWIdget 下的控件都有鼠标进入鼠标 离开方法
鼠标事件
鼠标进入 enterEvent
鼠标离开 leaveEvent
鼠标的按下,释放,移动
通过ev可以获取到 x,y坐标
判断鼠标左右键
等等吧
QString做格式化字符串 用%1 %2 .arg().arg()
定时器事件
timerEvent
定时器使用
timerEvent事件
启动定时器 startTimer(毫秒) 返回值就是Id号
区分定时器 timerId
定时器的第二种方式(推荐)
QTImer 头文件
创建QTimer *timer...
启动定时器timer->start(毫秒)
发送信号 timeout
暂停定时器 stop
Event
event事件包含了所有事件
做分发事情
event返回值 bool
bool event(QEvent *)
返回值用途 返回值为true 用户自己处理
事件 不往下分发
false 系统处理事件
event事件
主要功能 事件的分发
bool event(QEvent *e)
返回值如果是true 代表用户自己处理
false 系统处理 最好抛给父亲去处理
static_case<转换类型>(原对象)
e->type 具体事件
if (e->type()==QEvent::MouseButtonPress){}
事件过滤器
哪个控件需求过滤事件 就给哪个控件安装过滤器
步骤1 安装过滤器
ui->label->installEventFilter(this);
步骤2
重写事件
#-------------------------------------------------
#
# Project created by QtCreator 2019-08-17T09:23:09
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = 03_02_Event
TEMPLATE = app
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use depre