当前位置:网站首页>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 .
边栏推荐
- sqli-labs第2关
- 图像变换,转置
- sqli-labs(POST类型注入)
- Qt的右键菜单
- kubeadm部署kubernetes v1.23.5集群
- Npoi export word font size correspondence
- Luogu greedy part of the backpack line segment covers the queue to receive water
- NPOI 导出Word 字号对应
- Pclpy projection filter -- projection of point cloud to cylinder
- Minecraft air Island service
猜你喜欢
随机推荐
Solution of Xiaomi TV's inability to access computer shared files
STM32 new project (refer to punctual atom)
Oracle 相关统计
OpenFeign 简单使用
c语言将字符串中的空格替换成%20
kubeadm部署kubernetes v1.23.5集群
Openshift build image
Routing foundation - dynamic routing
图像变换,转置
gocv边界填充
What is SQL injection
Data asset management function
C language replaces spaces in strings with%20
gocv图片读取并展示
Finishing the interview essentials of secsha system!!!
C# 百度地图,高德地图,Google地图(GPS) 经纬度转换
随笔:RGB图像颜色分离(附代码)
Openshift container platform community okd 4.10.0 deployment
Detailed explanation of NIN network
Qunhui NAS configuring iSCSI storage