def sendEvent(self, event: QEvent) -> None: """ Send an event. Args: event: The event to send. """ if event.type() == QEvent.Type.FocusOut: # Ignored - cannot get focus back reliably :-( return if isinstance(event, QMouseEvent): # `windowPos` is replaced with `localPos` as it has no meaning in offscreen rendering. event = QMouseEvent(event.type(), event.localPos(), event.screenPos(), event.button(), event.buttons(), event.modifiers()) elif isinstance(event, QWheelEvent): event = QWheelEvent(event.position(), event.position(), event.pixelDelta(), event.angleDelta(), event.buttons(), event.modifiers(), event.phase(), event.inverted(), event.source()) self._window.contentItem().forceActiveFocus() QCoreApplication.sendEvent(self._window, event)
def eventFilter(self, watched_obj: QObject, event: QEvent): if event.type() == QEvent.MouseButtonPress or event.type( ) == QEvent.MouseButtonRelease: self.draw_brush_event(event) return True elif event.type() == QEvent.MouseMove: self.draw_brush_event(event) return False elif event.type() == QEvent.Wheel and event.modifiers( ) == Qt.ControlModifier: angle_delta_y = event.angleDelta().y() zoom_factor = 1 + np.sign(angle_delta_y) * 0.2 * abs( angle_delta_y) / 110 self.radius *= zoom_factor self.radius = max(self.radius, MIN_RADIUS) self.draw_brush_event(event) return True else: return super().eventFilter(watched_obj, event)