qt使用鼠标事件获取鼠标在QLabel和Ui界面中的点击位置
如标题所述功能的实现主要是需要重写鼠标事件,Widget 类里可以直接添加进去,QLabel类没有自带这一功能,所以需要重新定义一个自己手动添加了鼠标事件的类别。我之前的一篇博客可以作一下参考:
Qt 为QPushButton、QLabel添加鼠标移入移出事件
将我的工程文件都列在下面:
(qt自动生成)
mouse_position.pro
#-------------------------------------------------
#
# Project created by QtCreator 2020-01-16T21:26:03
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = mouse_position
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