当前位置:网站首页>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 .
边栏推荐
猜你喜欢
随机推荐
群辉 NAS 配置 iSCSI 存储
Kubernetes deploys Loki logging system
Driving test Baodian and its spokesperson Huang Bo appeared together to call for safe and civilized travel
sqli-labs第8关(布尔盲注)
Benefits of ufcs of D
Analysis of the use of comparable, comparator and clonable interfaces
Googlenet network explanation and model building
kubernetes部署loki日志系统
Web技术发展史
gocv opencv exit status 3221225785
Mutex
使用递归函数求解字符串的逆置问题
Data asset management function
[blackmail virus data recovery] suffix Crylock blackmail virus
gocv拆分颜色通道
Hcia - Application Layer
Minecraft群組服開服
KubeSphere 虚拟化 KSV 安装体验
sqli-labs第2关
commands out of sync. did you run multiple statements at once





![[blackmail virus data recovery] suffix Rook3 blackmail virus](/img/46/debc848d17767d021f3f41924cccfe.jpg)



