self.label1 = QtWidgets.QLabel() self.label2 = QtWidgets.QLabel() layout = QtWidgets.QVBoxLayout() layout.addWidget(self.label1) layout.addWidget(self.label2) self.setLayout(layout) self.label1.setText("Please drag a \"VCard\" from Contacts application, normally a name in the list, and drop here.") def dragEnterEvent(self, e): e.accept() def dropEvent(self, e): e.accept() self.contentsDropEvent(e) def contentsDropEvent(self, e): if e.mimeData().hasFormat("application/x-mycompany-VCard"): s = e.mimeData().data( "application/x-mycompany-VCard" ) # s now contains text of vcard self.label2.setText(str(s)) e.acceptProposedAction() if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) QtMacExtras.qRegisterDraggedTypes(["public.vcard"]) wid1 = TestWidget() wid1.show() sys.exit(app.exec_())
layout = QtWidgets.QVBoxLayout() layout.addWidget(self.label1) layout.addWidget(self.label2) self.setLayout(layout) self.label1.setText( "Please drag a \"VCard\" from Contacts application, normally a name in the list, and drop here." ) def dragEnterEvent(self, e): e.accept() def dropEvent(self, e): e.accept() self.contentsDropEvent(e) def contentsDropEvent(self, e): if e.mimeData().hasFormat("application/x-mycompany-VCard"): s = e.mimeData().data("application/x-mycompany-VCard") # s now contains text of vcard self.label2.setText(str(s)) e.acceptProposedAction() if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) QtMacExtras.qRegisterDraggedTypes(["public.vcard"]) wid1 = TestWidget() wid1.show() sys.exit(app.exec_())