当前位置:网站首页>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 .
边栏推荐
- Viewing JS array through V8
- Realization of basic function of sequence table
- 一个经典约瑟夫问题的分析与解答
- [blackmail virus data recovery] suffix Hydra blackmail virus
- C#钉钉开发:取得所有员工通讯录和发送工作通知
- zipkin 简单使用
- Qt——如何在QWidget中设置阴影效果
- Tensorflow2 keras classification model
- kubernetes部署loki日志系统
- Kubesphere virtualization KSV installation experience
猜你喜欢

C language replaces spaces in strings with%20

sqli-labs第8关(布尔盲注)

Minecraft plug-in service opening

Honeypot attack and defense drill landing application scheme

Openshift deployment application

Minecraft module service opening
![[blackmail virus data recovery] suffix Crylock blackmail virus](/img/b2/8e3a65dd250b9194cfc175138c740c.jpg)
[blackmail virus data recovery] suffix Crylock blackmail virus

Minecraft群组服开服
![[untitled]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled]

HCIA—应用层
随机推荐
C language replaces spaces in strings with%20
Classes and objects (instantiation of classes and classes, this, static keyword, encapsulation)
路由基础—动态路由
File upload Labs
Minecraft install resource pack
Count the number of various characters in the string
Realization of basic function of sequence table
ARP及ARP欺骗
sqli-labs第1关
文件上传-upload-labs
zipkin 简单使用
Web技术发展史
Qt的connect函数和disconnect函数
KubeSphere 虚拟化 KSV 安装体验
HCIA - application layer
C#钉钉开发:取得所有员工通讯录和发送工作通知
Detailed explanation of NIN network
[blackmail virus data recovery] suffix Crylock blackmail virus
Honeypot attack and defense drill landing application scheme
Function ‘ngram‘ is not defined