当前位置:网站首页>QT | mouse events and wheel events qmouseevent, qwheelevent
QT | mouse events and wheel events qmouseevent, qwheelevent
2022-07-25 10:40:00 【InfoQ】
Preface :
Mouse events :
- void mousePressEvent(QMouseEvent *event); // Mouse button down
- void mouseReleaseEvent(QMouseEvent *event); // Mouse button up
- void mouseDoubleClickedEvent(QMouseEvent *event); // Double click the mouse button
- void mouseMouveEvent(QMouseEvent *event); // Mouse movement
- void wheelEvent(QWheelEvent *event); // Scroll with the mouse wheel
Mouse movement events :
- Mouse movement event mouseMouveEvent() The default is when the mouse button is pressed and the mouse is moved ;
- If you don't want to press the mouse to get the mouse movement event , You need to add :
- setMouseTracking(true);// Set mouse tracking
Set the mouse shape :
QCursor cursor;
cursor.setShape(Qt::OpenHandCursor);// Small palm shape
setCursor(cursor);
// Or use :QApplication::setOverriedCursor(cursor);// Make the mouse pointer temporarily change shape
QCursor cursor("./image/logo.png");
setCursor(cursor);
// Or use :QApplication::setOverrideCursor(cursor);// Make the mouse pointer temporarily change shape
Q_UNUSED():
Wheel event :
- QWheelEvent() Class delta() Function returns the distance the scroll wheel moves .
- Whenever the roller rotates , The default is 15 degree , Call at this time QWheelEvent()::delta() The value returned is 15*8=120.
- The direction of rotation is outward , Returns a positive value ; The direction of rotation is inward , Returns a negative value . So you can judge the direction of the roller by the positive and negative return value of this function .
Drag the mouse to move the window :
void Widget::mousePressEvent(QMouseEvent *event)
{
if(event->button() == Qt::LeftButton) // Left mouse button
{
m_isMouseLeftDown = true;
m_dragPos = event->globalPos() - pos(); // Get the difference between the pointer position and the window position
}
}
void Widget::mouseMoveEvent(QMouseEvent *event)
{
if(event->buttons() & Qt::LeftButton)// See note :
{
move(event->globalPos() - m_dragPos);
event->accept(); // Event handler “ receive ” The incident happened , Do not pass to the parent part ;
}
}
Realize the scroll wheel to enlarge or shrink the content in the editor :
void Widget::wheelEvent(QWheelEvent *event)
{
if(event->delta() > 0)
{
ui->textEdit->zoomIn();// Zoom in
}
else
{
ui->textEdit->zoomOut();// narrow
}
}边栏推荐
- Multithreading -- callable interface, lambda
- MySQL solves the problem of not supporting Chinese
- 推荐系统-协同过滤在Spark中的实现
- Attention is all you need paper intensive reading notes transformer
- Angr(十)——官方文档(Part1)
- 云原生IDE:iVX免费的首个通用无代码开发平台
- Deploy master-slave database
- Test plan and test plan
- Pytorch code template (CNN)
- Software test notes, test case design
猜你喜欢

Open virtual private line network load balancing

1.Shell编程规范与变量

云原生IDE:iVX免费的首个通用无代码开发平台

11.iptables 防火墙

微波技术大作业课设-分立电容电感+微带单枝短截线+微带双枝短截线

3.跟你思想一样DNS域名解析服务!!!

6.shell之正则表达式

2021 牛客网笔试总结 02

CONDA configures the deep learning environment pytorch transformers

Upgrade glibc 2.29 checking LD_ LIBRARY_ Path variable... Contains current directory error solution
随机推荐
When installing mysql, string the service installation failure > mysql80 startup failure
Open虚拟专线网络负载均衡
Idea overall font size modification
微波技术大作业课设-分立电容电感+微带单枝短截线+微带双枝短截线
美国机场围棋风格可视化专题图:ArcGIS Pro版本
After switching the shell command line terminal (bash/zsh), CONDA cannot be used: command not found
9.shell文本处理三剑客之awk
2、 What does the unittest framework do
VLAN configuration and application (take Huawei ENSP as an example)
Redis usage scenario
ONNX Runtime介绍
9. Shell text processing three swordsmen awk
Selenium waits for the occurrence of elements and the conditions under which the waiting operation can be performed
Mysql离线部署
5.这简单的 “echo” 用法隔壁小孩能不会吗!
js 集合
如何通过开源数据库管理工具 DBeaver 连接 TDengine
2021 jd.com written examination summary
思路再次完美验证!加息临近,趋势明了,好好把握这波行情!
微信小程序WxPrase中包含文件无法点击解决