当前位置:网站首页>QT drag event
QT drag event
2022-07-02 08:50:00 【Code pirate captain】
Qt File drag event
1、 How to make qt The interface recognizes the dragged file ?
Add the following code to the interface constructor
setAcceptDrops(true);// Set drag-and-drop support
In this way, drag the file to Qt Program interface , It will trigger Qt Drag events for ;
2、 How to handle the operation of dragging files
QWidget Class and inheritance QWidget Subclasses of , You can rewrite drag events through the defined virtual function interface . These four related virtual functions are
void dragEnterEvent(QDragEnterEvent *event); // Drag into Qt Triggered when the desktop control
void dragMoveEvent(QDragMoveEvent *event); // Drag on Qt Triggered when moving within the desktop control
void dragLeaveEvent(QDragLeaveEvent *event); // Drag away Qt Triggered when the desktop control
void dropEvent(QDropEvent *event); // Put down the file in Qt Triggered when the desktop control
void Widget::dragEnterEvent(QDragEnterEvent *event)
{
qDebug()<<event->type();
if (event->mimeData()->hasFormat("text/uri-list")) // Determine if it's a document
{
event->acceptProposedAction();
}
}
void Widget::dragMoveEvent(QDragMoveEvent *event)
{
qDebug()<<event->type();
}
void Widget::dragLeaveEvent(QDragLeaveEvent *event)
{
qDebug()<<event->type();
}
void Widget::dropEvent(QDropEvent *event)
{
qDebug()<<event->type();
QList<QUrl> urls = event->mimeData()->urls();
qDebug()<<urls;
setText(urls[0].toString());
}
As you can see from the code , Drag files to Qt Control , Not only a single file is supported , It also supports dragging and dropping multiple files , Through the code above , Pass the path of the dragged file to Qt Control .
边栏推荐
- Gateway 简单使用
- gocv拆分颜色通道
- Minecraft air Island service
- Programmer training, crazy job hunting, overtime ridiculed by colleagues deserve it
- Count the number of various characters in the string
- Method recursion (Fibonacci sequence, frog jumping steps, tower of Hanoi problem)
- 判断是否是数独
- Sentinel 简单使用
- c语言自定义类型枚举,联合(枚举的巧妙使用,联合体大小的计算)
- 随笔:RGB图像颜色分离(附代码)
猜你喜欢

Kubernetes deploys Loki logging system

Linux binary installation Oracle database 19C

Nacos download, start and configure MySQL database

Linux安装Oracle Database 19c

什么是SQL注入

Honeypot attack and defense drill landing application scheme

ARP and ARP Spoofing

Implementation of bidirectional linked list (simple difference, connection and implementation between bidirectional linked list and unidirectional linked list)

Sqli labs level 12

C language replaces spaces in strings with%20
随机推荐
Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
sqli-labs第1关
Makefile基本原理
Minecraft air Island service
libusb的使用
c语言自定义类型——结构体,位段(匿名结构体,结构体的自引用,结构体的内存对齐)
Kubesphere virtualization KSV installation experience
Openshift build image
Minecraft群組服開服
将一串数字顺序后移
Sqli labs level 12
Sqli labs (post type injection)
小米电视不能访问电脑共享文件的解决方案
Gateway is easy to use
HCIA—應用層
Tensorflow2 keras classification model
C nail development: obtain all employee address books and send work notices
ARP及ARP欺骗
IP协议与IP地址
gocv图片读取并展示