-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDragAcceptableQLine.py
More file actions
30 lines (26 loc) · 975 Bytes
/
DragAcceptableQLine.py
File metadata and controls
30 lines (26 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from PyQt6.QtWidgets import QLineEdit
from PyQt6.QtCore import pyqtSignal
class DragAcceptableQLine(QLineEdit):
dropAccepted = pyqtSignal()
"""实现文件拖放功能"""
def __init__(self, parent=None):
super().__init__(parent)
self.setAcceptDrops(True)
def dragEnterEvent(self, event):
data = event.mimeData()
urls = data.urls()
if (urls and urls[0].scheme() == 'file'):
event.acceptProposedAction()
def dragMoveEvent(self, event):
data = event.mimeData()
urls = data.urls()
if urls and urls[0].scheme() == 'file':
event.acceptProposedAction()
def dropEvent(self, event):
data = event.mimeData()
urls = data.urls()
if urls and urls[0].scheme() == 'file':
# for some reason, this doubles up the intro slash
filepath = str(urls[0].path())[1:]
self.setText(filepath)
self.dropAccepted.emit()