def mouseMoveEvent(self, event: QMouseEvent): self.logger.debug("触发鼠标移动事件") super().mouseMoveEvent(event) if self.m_flag == True: delta_x = int(event.globalPosition().x() - self.old_pos.x()) delta_y = int(event.globalPosition().y() - self.old_pos.y()) self.move(self.x() + delta_x, self.y() + delta_y) #更改窗口位置 self.logger.debug("已更改窗口位置") self.old_pos = event.globalPosition()
def mousePressEvent(self, event: QMouseEvent): self.logger.debug("触发鼠标按压事件") super().mousePressEvent(event) self.setFocus() self.m_flag = True if event.button() == Qt.MouseButtons.LeftButton and self.isMaximized( ) == False and self.hasFocus() == True: self.old_pos = event.globalPosition() #获取鼠标相对窗口的位置 self.logger.debug("已获取鼠标位置") self.setCursor(QtGui.QCursor( Qt.CursorShape.SizeAllCursor)) #更改鼠标图标
def mouseMoveEvent(self, event: QtGui.QMouseEvent) -> None: x, y = event.pos().x(), event.pos().y() x, y = self.gr_field.pixel_to_norm_coord(x, y) for zone in self.gr_field.zones: if zone.coordinates_are_in_zone(x, y): if not zone.activated: zone.mouse_enter.emit() zone.activated = True else: if zone.activated: zone.mouse_leave.emit() zone.activated = False
def mouseMoveEvent(self, event: QtGui.QMouseEvent) -> None: x, y = event.pos().x(), event.pos().y() if self.__mode == 'select' and self.__mouse_is_pressed: self.__select_end = (x, y) self.update() elif self.__mode == 'grab' and self.__mouse_is_pressed: end = (x, y) dx = end[0] - self.__move_start[0] dy = end[1] - self.__move_start[1] self.zoom_x = self.__zoom_x0 - self.pixel_to_norm_rel(dx) self.zoom_y = self.__zoom_y0 - self.pixel_to_norm_rel(dy) self.zoomed.emit()
def mousePressEvent(self, event: QtGui.QMouseEvent) -> None: x, y = event.pos().x(), event.pos().y() if self.__mode == 'select': self.__select = True self.__select_start = (x, y) self.__select_end = (x, y) elif self.__mode == 'grab': self.setCursor(Qt.CursorShape.ClosedHandCursor) self.__move_start = (x, y) self.__zoom_x0 = self.zoom_x self.__zoom_y0 = self.zoom_y else: x, y = self.pixel_to_norm_coord(x, y) for zone in self.zones: if zone.coordinates_are_in_zone(x, y): zone.clicked.emit() self.__mouse_is_pressed = True
def mouseReleaseEvent(self, event: QtGui.QMouseEvent) -> None: self.__mouse_is_pressed = False if self.__mode == 'select': self.__select_end = (event.pos().x(), event.pos().y()) width = self.__select_end[0] - self.__select_start[0] height = self.__select_end[1] - self.__select_start[1] self.zoom_x, self.zoom_y = self.pixel_to_norm_coord( self.__select_start[0], self.__select_start[1]) self.zoom_x += self.margin self.zoom_y += self.margin if width < 0: width = abs(width) self.zoom_x -= self.pixel_to_norm_rel(width) if height < 0: height = abs(height) self.zoom_y -= self.pixel_to_norm_rel(height) if width <= height * self.x_range / self.y_range: self.zoom_w = self.pixel_to_norm_rel(width) else: self.zoom_w = self.pixel_to_norm_rel(height * self.x_range / self.y_range) if self.zoom_w <= 2 * self.margin: self.zoom_w = 0 else: self.zoom_w -= 2 * self.margin self.__select = False self.zoomed.emit() elif self.__mode == 'grab': self.setCursor(Qt.CursorShape.OpenHandCursor)
def mouseDoubleClickEvent(self, event: QtGui.QMouseEvent) -> None: x, y = self.pixel_to_norm_coord(event.pos().x(), event.pos().y()) for zone in self.zones: if zone.coordinates_are_in_zone(x, y): zone.double_clicked.emit()