Created
March 16, 2021 08:41
-
-
Save zclongpop123/2768bbbb2d3824629c7fde252395860b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #======================================== | |
| # author: Changlong.Zang | |
| # mail: [email protected] | |
| # time: Tue Dec 29 17:17:55 2020 | |
| #======================================== | |
| import sys | |
| import os | |
| from PySide2 import QtWidgets, QtGui, QtCore | |
| import widgets | |
| #--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ | |
| class TestListView(QtWidgets.QListWidget): | |
| fileDropped = QtCore.Signal(list) | |
| def __init__(self, type, parent=None): | |
| super(TestListView, self).__init__(parent) | |
| self.setAcceptDrops(True) | |
| self.setIconSize(QtCore.QSize(72, 72)) | |
| def dragEnterEvent(self, event): | |
| if event.mimeData().hasUrls: | |
| event.accept() | |
| else: | |
| event.ignore() | |
| def dragMoveEvent(self, event): | |
| if event.mimeData().hasUrls: | |
| event.setDropAction(QtCore.Qt.CopyAction) | |
| event.accept() | |
| else: | |
| event.ignore() | |
| def dropEvent(self, event): | |
| if event.mimeData().hasUrls: | |
| event.setDropAction(QtCore.Qt.CopyAction) | |
| event.accept() | |
| links = [] | |
| for url in event.mimeData().urls(): | |
| links.append(str(url.toLocalFile())) | |
| self.fileDropped.emit(links) | |
| else: | |
| event.ignore() | |
| class MainForm(QtWidgets.QMainWindow): | |
| def __init__(self, parent=None): | |
| super(MainForm, self).__init__(parent) | |
| self.view = TestListView(self) | |
| self.view.fileDropped.connect(self.pictureDropped) | |
| self.setCentralWidget(self.view) | |
| def pictureDropped(self, l): | |
| for url in l: | |
| if os.path.exists(url): | |
| print(url) | |
| icon = QtGui.QIcon(url) | |
| pixmap = icon.pixmap(72, 72) | |
| icon = QtGui.QIcon(pixmap) | |
| item = QtWidgets.QListWidgetItem(url, self.view) | |
| item.setIcon(icon) | |
| item.setStatusTip(url) | |
| # class PublishUI(QtWidgets.QMainWindow, widgets.Ui_MainWindow): | |
| # ''' | |
| # ''' | |
| # def __init__(self): | |
| # ''' | |
| # ''' | |
| # super().__init__() | |
| # self.setupUi(self) | |
| def main(): | |
| app = QtWidgets.QApplication(sys.argv) | |
| ui = MainForm() | |
| ui.show() | |
| sys.exit(app.exec_()) | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment