def eventFilter(self, source, event: QtCore.QEvent): if source is self._scene: if event.type() == QtCore.QEvent.GraphicsSceneMouseRelease and\ event.button() == QtCore.Qt.LeftButton and\ event.scenePos().x() >= 0 and event.scenePos().x() < self._scene.width() and\ event.scenePos().y() >= 0 and event.scenePos().y() < self._scene.height(): pos = event.scenePos() box_clicked_x = self.windowToSquareX(pos.x()) box_clicked_y = self.windowToSquareYInv(pos.y()) new_origin = int(box_clicked_x + box_clicked_y * self.hor_pixels) if not self.shift_down: self.curr_origins.clear() self.curr_origins.add(new_origin) print(self.curr_origins) self.originsUpdated.emit(self.curr_origins) elif event.type() == QtCore.QEvent.GraphicsSceneMouseMove: self.onMouseHover(event.scenePos()) elif event.type() == QtCore.QEvent.KeyPress: if event.key() == QtCore.Qt.Key_Shift: self.shift_down = True elif event.type() == QtCore.QEvent.KeyRelease: if event.key() == QtCore.Qt.Key_Shift: self.shift_down = False return widgets.QWidget.eventFilter(self, source, event)
def _getHitPortItemOrNone(self, event: QEvent) -> _tp.Optional[PortItemBase]: fromPort = self._currentlyDraggedConnectionFromPort mousePosition = event.scenePos() relevantPortItems = self._getRelevantHitPortItems( mousePosition, fromPort) if not relevantPortItems: return None numberOfHitPortsItems = len(relevantPortItems) if numberOfHitPortsItems > 1: raise NotImplementedError( "Can't deal with overlapping port items.") hitPortItem = relevantPortItems[0] return hitPortItem