Skip to content

Instantly share code, notes, and snippets.

@paulwinex
Last active October 13, 2017 05:22
Show Gist options
  • Save paulwinex/f9c75967ac141aa8ea9fa61d5b64e8aa to your computer and use it in GitHub Desktop.
Save paulwinex/f9c75967ac141aa8ea9fa61d5b64e8aa to your computer and use it in GitHub Desktop.
from PySide.QtGui import *
from PySide.QtCore import *
class MainWindow(QWidget):
def __init__(self):
super(MainWindow, self).__init__()
self.ly = QVBoxLayout(self)
self.setLayout(self.ly)
self.list = ListClass()
self.ly.addWidget(self.list)
# 2 - connect custom signal
self.list.itemDroppedSignal.connect(self.add_new_item)
def add_new_item(self, url):
print url
item = QListWidgetItem()
item.setText(url)
self.list.addItem(item)
class ListClass(QListWidget):
# 1 - create custom signal
itemDroppedSignal = Signal(object)
def __init__(self):
super(ListClass, self).__init__()
self.setAcceptDrops(True)
def dropEvent(self, event):
mime = event.mimeData()
if mime.hasUrls():
for url in mime.urls():
# 3 - emit custom signal
self.itemDroppedSignal.emit(url.toLocalFile())
# self.add_item(url.toLocalFile())
def dragEnterEvent(self, event):
event.accept()
def dragMoveEvent(self, event):
event.accept()
def add_item(self, path):
item = QListWidgetItem()
item.setText(path)
self.addItem(item)
if __name__ == '__main__':
app = QApplication([])
w = MainWindow()
w.show()
app.exec_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment