I am learning the drag and drop part of pyqt5. However, most files can be dragged and dropped, but only Outlook's mail is impossible. (I need the location of the file) I am looking for help because the Outlook mail is stored in a .pst format file and does not seem to be dragged and dropped immediately. There are two options I thought of. First, drag and drop directly from Outlook to register mail path in pyqt. Second, if you drag it from Outlook to pyqt, download the mail to a specific location and register the path in pyqt.
Is there a better way? Or can you give me advice on the two methods I suggested?
import sys
from PyQt5.QtCore import Qt, QFile, QIODevice, QDataStream
from PyQt5.QtWidgets import QApplication, QMainWindow, QListWidget, QListWidgetItem, QPushButton
class ListBoxWidget(QListWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setAcceptDrops(True)
self.resize(600, 600)
def dragEnterEvent(self, event):
if event.mimeData().hasUrls:
event.accept()
else:
event.ignore()
def dragMoveEvent(self, event):
if event.mimeData().hasUrls():
event.setDropAction(Qt.CopyAction)
event.accept()
elif event.mimeData().hasFormat("FileContents"):
"""
1. How can I drag the OUTLOOK mail right away?
2. How can I download OUTLOOK mail when it enters the PYQT area?
"""
else:
event.ignore()
def dropEvent(self, event):
if event.mimeData().hasUrls():
event.setDropAction(Qt.CopyAction)
event.accept()
links = []
for url in event.mimeData().urls():
# https://doc.qt.io/qt-5/qurl.html
if url.isLocalFile():
links.append(str(url.toLocalFile()))
else:
links.append(str(url.toString()))
self.addItems(links)
else:
event.ignore()
class AppDemo(QMainWindow):
def __init__(self):
super().__init__()
self.resize(1200, 600)
self.listbox_view = ListBoxWidget(self)
self.btn = QPushButton('Get Value', self)
self.btn.setGeometry(850, 400, 200, 50)
self.btn.clicked.connect(lambda: print(self.getSelectedItem()))
def getSelectedItem(self):
item = QListWidgetItem(self.listbox_view.currentItem())
return item.text()
if __name__ == '__main__':
app = QApplication(sys.argv)
demo = AppDemo()
demo.show()
sys.exit(app.exec_())
It's not easy to find data on PYQT5. Please help me.