当前位置:网站首页>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 .
边栏推荐
- Use the numbers 5, 5, 5, 1 to perform four operations. Each number should be used only once, and the operation result value is required to be 24
- Minecraft模组服开服
- Loadbalancer dynamically refreshes Nacos server
- Oracle related statistics
- Sentinel easy to use
- C# 高德地图 根据经纬度获取地址
- Find the node with the smallest value range in the linked list and move it to the front of the linked list
- Hcia - Application Layer
- commands out of sync. did you run multiple statements at once
- Googlenet network explanation and model building
猜你喜欢

HCIA—应用层

kubeadm部署kubernetes v1.23.5集群

sqli-labs(POST类型注入)

Honeypot attack and defense drill landing application scheme

commands out of sync. did you run multiple statements at once

Application of kotlin - higher order function

Openshift container platform community okd 4.10.0 deployment

Use Wireshark to grab TCP three handshakes

Minecraft群组服开服

Kubernetes deploys Loki logging system
随机推荐
HCIA—應用層
Openshift build image
Qt——如何在QWidget中设置阴影效果
Finishing the interview essentials of secsha system!!!
Gateway 简单使用
C Baidu map, Gaode map, Google map (GPS) longitude and latitude conversion
Pointer initialization
Minecraft module service opening
Classes and objects (instantiation of classes and classes, this, static keyword, encapsulation)
gocv opencv exit status 3221225785
OpenShift 部署应用
统计字符串中各类字符的个数
Qt的右键菜单
Function ‘ngram‘ is not defined
Programmer training, crazy job hunting, overtime ridiculed by colleagues deserve it
一、Qt的核心类QObject
Sqli labs Level 2
Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
Method recursion (Fibonacci sequence, frog jumping steps, tower of Hanoi problem)
k8s入门:Helm 构建 MySQL