def wheelEvent(self, a0: QtGui.QWheelEvent) -> None: if len(self.tdrWindow.td) == 0: a0.ignore() return chart_height = self.chartHeight chart_width = self.chartWidth do_zoom_x = do_zoom_y = True if a0.modifiers() == QtCore.Qt.ShiftModifier: do_zoom_x = False if a0.modifiers() == QtCore.Qt.ControlModifier: do_zoom_y = False if a0.angleDelta().y() > 0: # Zoom in a0.accept() # Center of zoom = a0.x(), a0.y() # We zoom in by 1/10 of the width/height. rate = a0.angleDelta().y() / 120 if do_zoom_x: zoomx = rate * chart_width / 10 else: zoomx = 0 if do_zoom_y: zoomy = rate * chart_height / 10 else: zoomy = 0 absx = max(0, a0.x() - self.leftMargin) absy = max(0, a0.y() - self.topMargin) ratiox = absx / chart_width ratioy = absy / chart_height # TODO: Change zoom to center on the mouse if possible, or extend box to the side that has room if not. p1x = int(self.leftMargin + ratiox * zoomx) p1y = int(self.topMargin + ratioy * zoomy) p2x = int(self.leftMargin + chart_width - (1 - ratiox) * zoomx) p2y = int(self.topMargin + chart_height - (1 - ratioy) * zoomy) self.zoomTo(p1x, p1y, p2x, p2y) elif a0.angleDelta().y() < 0: # Zoom out a0.accept() # Center of zoom = a0.x(), a0.y() # We zoom out by 1/9 of the width/height, to match zoom in. rate = -a0.angleDelta().y() / 120 if do_zoom_x: zoomx = rate * chart_width / 9 else: zoomx = 0 if do_zoom_y: zoomy = rate * chart_height / 9 else: zoomy = 0 absx = max(0, a0.x() - self.leftMargin) absy = max(0, a0.y() - self.topMargin) ratiox = absx / chart_width ratioy = absy / chart_height p1x = int(self.leftMargin - ratiox * zoomx) p1y = int(self.topMargin - ratioy * zoomy) p2x = int(self.leftMargin + chart_width + (1 - ratiox) * zoomx) p2y = int(self.topMargin + chart_height + (1 - ratioy) * zoomy) self.zoomTo(p1x, p1y, p2x, p2y) else: a0.ignore()
def wheelEvent(self, a0: QtGui.QWheelEvent) -> None: if len(self.data) == 0 and len(self.reference) == 0: a0.ignore() return do_zoom_x = do_zoom_y = True if a0.modifiers() == QtCore.Qt.ShiftModifier: do_zoom_x = False if a0.modifiers() == QtCore.Qt.ControlModifier: do_zoom_y = False if a0.angleDelta().y() > 0: # Zoom in a0.accept() # Center of zoom = a0.x(), a0.y() # We zoom in by 1/10 of the width/height. rate = a0.angleDelta().y() / 120 if do_zoom_x: zoomx = rate * self.chartWidth / 10 else: zoomx = 0 if do_zoom_y: zoomy = rate * self.chartHeight / 10 else: zoomy = 0 absx = max(0, a0.x() - self.leftMargin) absy = max(0, a0.y() - self.topMargin) ratiox = absx / self.chartWidth ratioy = absy / self.chartHeight p1x = int(self.leftMargin + ratiox * zoomx) p1y = int(self.topMargin + ratioy * zoomy) p2x = int(self.leftMargin + self.chartWidth - (1 - ratiox) * zoomx) p2y = int(self.topMargin + self.chartHeight - (1 - ratioy) * zoomy) self.zoomTo(p1x, p1y, p2x, p2y) elif a0.angleDelta().y() < 0: # Zoom out a0.accept() # Center of zoom = a0.x(), a0.y() # We zoom out by 1/9 of the width/height, to match zoom in. rate = -a0.angleDelta().y() / 120 if do_zoom_x: zoomx = rate * self.chartWidth / 9 else: zoomx = 0 if do_zoom_y: zoomy = rate * self.chartHeight / 9 else: zoomy = 0 absx = max(0, a0.x() - self.leftMargin) absy = max(0, a0.y() - self.topMargin) ratiox = absx / self.chartWidth ratioy = absy / self.chartHeight p1x = int(self.leftMargin - ratiox * zoomx) p1y = int(self.topMargin - ratioy * zoomy) p2x = int(self.leftMargin + self.chartWidth + (1 - ratiox) * zoomx) p2y = int(self.topMargin + self.chartHeight + (1 - ratioy) * zoomy) self.zoomTo(p1x, p1y, p2x, p2y) else: a0.ignore()
def wheelEvent(self, event: QtGui.QWheelEvent): imgrect = self.imglabel.geometry() delta = event.angleDelta().y() # x,y 为映射不变点坐标 if imgrect.x() < event.x() < (imgrect.x() + imgrect.width()) and \ imgrect.y() < event.y() < (imgrect.y() + imgrect.height()): x = int(event.x() - imgrect.x()) y = int(event.y() - imgrect.y()) else: x = imgrect.width() // 2 y = imgrect.height() // 2 # 根据 delta 来判断滚轮方向 if delta > 0: self.imglabel.resizeImg(x, y, 1, x, y) if delta < 0: self.imglabel.resizeImg(x, y, -1, x, y)
def wheelEvent(self, event: QWheelEvent): if self.zoom_enabled: delta = event.angleDelta().y() curscale = self.scale() mx_before = (event.x() - self.x_offset) / curscale my_before = (event.y() - self.y_offset) / curscale self.zoom += delta / 240 scale = self.scale() mx_after = (event.x() - self.x_offset) / scale my_after = (event.y() - self.y_offset) / scale self.x_offset -= (mx_before - mx_after) * scale self.y_offset -= (my_before - my_after) * scale self.every = max( 1, int(0.25*self.gridsize * self.gridsize/scale)) self.onGridSizeChange.emit(self.every) self.repaint()
def wheelEvent(self, event: QWheelEvent): (x, y) = self.transform_mouse_coordinates(event.x(), event.y()) delta_scale = 0.1 if event.angleDelta().y() > 0: self.scale += delta_scale elif self.scale <= delta_scale * 2: return else: self.scale -= delta_scale delta_x = x * delta_scale delta_y = y * delta_scale if event.angleDelta().y() > 0: self.offset -= QPoint(delta_x, delta_y) else: self.offset += QPoint(delta_x, delta_y) self.repaint()