You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
540 B

1 month ago
from PyQt5 import QtCore, QtGui, QtWidgets
class MyQLine(QtWidgets.QLineEdit):
"""实现文件拖放功能"""
def __init__(self, parent=None):
super().__init__(parent)
self.setAcceptDrops(True)
def dragEnterEvent(self, e):
if e.mimeData().text().endswith('.xlsx'): # 这里只接受拖入srt文件,别的文件拖入无效
e.accept()
else:
e.ignore()
def dropEvent(self, e):
path = e.mimeData().text().replace('file:///', '')
self.setText(path)