class ItemViewDragStartEventListener(QObject): dragStarted = Signal(QModelIndex) def __init__(self, parent=None): QObject.__init__(self, parent) self._pos = None self._index = None def eventFilter(self, viewport, event): view = viewport.parent() if event.type() == QEvent.MouseButtonPress and \ event.button() == Qt.LeftButton: index = view.indexAt(event.pos()) if index is not None: self._pos = event.pos() self._index = QPersistentModelIndex(index) elif event.type() == QEvent.MouseMove and self._pos is not None and \ ((self._pos - event.pos()).manhattanLength() >= QApplication.startDragDistance()): if self._index.isValid(): # Map to a QModelIndex in the model. index = self._index index = index.model().index(index.row(), index.column(), index.parent()) self._pos = None self._index = None self.dragStarted.emit(index) return QObject.eventFilter(self, view, event)
class Worker(QObject): """ Problems/issues: - None major? - Minor: reload when in progress aborts the currently running one resulting in a timeout in 60 sec. which overwrites the data. Fixed by removing self.cancelSearch() in LDAPTreeItem but should be properly fixed instead. (Removing cancel?) """ # Emitted by the workerThread when finished listFetched = pyqtSignal(QModelIndex, tuple) def __init__(self, parentIndex, parentItem): super(Worker, self).__init__() self.parentIndex = parentIndex self.persistent = QPersistentModelIndex(parentIndex) self.parentItem = parentItem self.parentItem.loading = True @pyqtSlot() def start(self): tupel = self.parentItem.fetchChildList() if self.persistent.isValid(): # QPersistenModelIndex -> QModelIndex # Should prefferably not be done here (changes can happend until the receiver-thread process the event) # but Qt can't send QPersistentModelIndexes (yet?) # Also, using QModelIndex through the whole process also works for some reason. # The new items are placed right even though QModelIndex.row() is wrong (e.g. because index = QModelIndex(self.persistent) self.listFetched.emit(index, tupel)
class Worker(QObject): """ Problems/issues: - None major? - Minor: reload when in progress aborts the currently running one resulting in a timeout in 60 sec. which overwrites the data. Fixed by removing self.cancelSearch() in LDAPTreeItem but should be properly fixed instead. (Removing cancel?) """ # Emitted by the workerThread when finished listFetched = pyqtSignal(QModelIndex, tuple) def __init__(self, parentIndex, parentItem): super(Worker, self).__init__() self.parentIndex = parentIndex self.persistent = QPersistentModelIndex(parentIndex) self.parentItem = parentItem self.parentItem.loading = True @pyqtSlot() def start(self): tupel = self.parentItem.fetchChildList() if self.persistent.isValid(): # QPersistenModelIndex -> QModelIndex # Should prefferably not be done here (changes can happend until the receiver-thread process the event) # but Qt can't send QPersistentModelIndexes (yet?) # Also, using QModelIndex through the whole process also works for some reason. # The new items are placed right even though QModelIndex.row() is wrong (e.g. because index = QModelIndex(self.persistent) self.listFetched.emit(index, tupel)
class ItemViewDragStartEventListener(QObject): dragStarted = Signal(QModelIndex) def __init__(self, parent=None): QObject.__init__(self, parent) self._pos = None self._index = None def eventFilter(self, viewport, event): view = viewport.parent() if event.type() == QEvent.MouseButtonPress and \ event.button() == Qt.LeftButton: index = view.indexAt(event.pos()) if index is not None: self._pos = event.pos() self._index = QPersistentModelIndex(index) elif event.type() == QEvent.MouseMove and self._pos is not None and \ ((self._pos - event.pos()).manhattanLength() >= QApplication.startDragDistance()): if self._index.isValid(): # Map to a QModelIndex in the model. index = self._index index = index.model().index(index.row(), index.column(), index.parent()) self._pos = None self._index = None self.dragStarted.emit(index) return QObject.eventFilter(self, view, event)