-
Notifications
You must be signed in to change notification settings - Fork 1
/
myQlistwidget.py
48 lines (37 loc) · 1.52 KB
/
myQlistwidget.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from PySide6.QtWidgets import QListView, QListWidget
from PySide6.QtCore import Qt
#from PySide6.QtGui import QStandardItemModel, QStandardItem
class myQListWidget(QListWidget):
def __init__(self, parent=None):
super().__init__()
self.mediaExt = ['mp4', 'mkv', 'wmv', 'avi']
#self.filelistModel = QStandardItemModel()
# self.setModel(self.filelistModel)
def dragEnterEvent(self, event):
if event.mimeData().hasUrls():
event.accept()
else:
event.ignore()
def dragMoveEvent(self, event):
pass
def dropEvent(self, event): # 放下文件后的动作
for u in event.mimeData().urls():
fileurl = str(u.toLocalFile())
if fileurl.split(".")[-1].lower() in self.mediaExt:
self.addItem(fileurl)
def keyPressEvent(self, event):
if event.key() == Qt.Key_Delete:
self._del_item()
def _del_item(self):
for item in self.selectedItems():
self.takeItem(self.row(item))
"""
flags = Qt.ItemIsEnabled | Qt.ItemIsDragEnabled | Qt.ItemIsSelectable
for u in event.mimeData().urls():
fileurl = str(u.toLocalFile())
print(fileurl.split(".")[-1])
if fileurl.split(".")[-1].lower() in self.mediaExt:
filelistItem = QStandardItem(fileurl)
filelistItem.setFlags(flags)
self.filelistModel.appendRow(filelistItem)
"""