def mousePressEvent(self, event): # grabbing the position of the widget sp = self.mapToScene(event.pos()) ret = self.scene().areaAt(sp) edge = ret % 100 iArea = int(ret / 100) - 1 # resizing/moving the area if it exists if edge: self.bResizing = True self.resizingEdge = edge self.resizingArea = self.scene().areas[iArea] self.resizingStartingPos = sp self.resizingAreaRect = self.resizingArea.rect() self.resizingAreaPos = self.resizingArea.pos() self.resizingArea.setFlag(QGraphicsItem.ItemIsMovable, False) # creation of a new area if there is an image elif iArea == -1 and self.filename: size = QSizeF(0, 0) newArea = self.scene().createArea(sp, size, self.areaType, self.areaBorder, self.areaTextSize) self.bResizing = True self.resizingEdge = 10 self.resizingArea = newArea self.resizingStartingPos = sp self.resizingAreaRect = self.resizingArea.rect() self.resizingAreaPos = self.resizingArea.pos() self.resizingArea.setFlag(QGraphicsItem.ItemIsMovable, False) QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): # grabbing the position of the widget sp = self.mapToScene(event.pos()) ret = self.scene().areaAt(sp) edge = ret % 100 iArea = int(ret / 100) - 1 # resizing/moving the area if it exists if edge: self.bResizing = True self.resizingEdge = edge self.resizingArea = self.scene().areas[iArea] self.resizingStartingPos = sp self.resizingAreaRect = self.resizingArea.rect() self.resizingAreaPos = self.resizingArea.pos() self.resizingArea.setFlag(QGraphicsItem.ItemIsMovable, False) # creation of a new area if there is an image elif iArea == -1 and self.filename: size = QSizeF(0, 0) newArea = self.scene().createArea(sp, size, self.areaType, self.areaBorder, self.areaTextSize) self.bResizing = True self.resizingEdge = 10 self.resizingArea = newArea self.resizingStartingPos = sp self.resizingAreaRect = self.resizingArea.rect() self.resizingAreaPos = self.resizingArea.pos() self.resizingArea.setFlag(QGraphicsItem.ItemIsMovable, False) QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): if event.button() == self.fMiddleButton: self.fPanning = True self.setDragMode(QGraphicsView.ScrollHandDrag) event = QMouseEvent(event.type(), event.pos(), Qt.LeftButton, Qt.LeftButton, event.modifiers()) QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, e): logger.debug('mousePressEvent') if e.button( ) == Qt.LeftButton: # and e.modifiers() & Qt.ControlModifier self.click_pos = e.pos() self.rs_center = self.sceneRect().center() QGraphicsView.mousePressEvent(self, e)
def mousePressEvent(self, event): """Go to the next / previous image, or be able to drag the image with a hand.""" if self.rband_state == "initial": self.rband = QRubberBand(QRubberBand.Rectangle, self) self.rband_origin = event.pos() self.rband.setGeometry(QRect(self.rband_origin, QSize())) self.rband.show() self.rband_state = "set-endpoint" elif self.rband_state == "drawn": if self.rband_corner == "nw": self.rband_state = "set-origin" elif self.rband_corner == "se": self.rband_state = "set-endpoint" elif self.rband_corner == "inside": self.rband_state = "move" self.setCursor(QCursor(Qt.ClosedHandCursor)) self.rband_previous_pos = event.pos() else: if event.button() == Qt.LeftButton: x = event.x() if x < 100: self.go_prev_img() elif x > self.width() - 100: self.go_next_img() else: self.setDragMode(QGraphicsView.ScrollHandDrag) QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): """ Start mouse pan or zoom mode. """ scenePos = self.mapToScene(event.pos()) if event.button() == Qt.LeftButton: # if self.panEnabled: if self.panEnabled or (event.modifiers() & Qt.ControlModifier): self.setDragMode(QGraphicsView.ScrollHandDrag) clippedCoords = self.clipScenePos(scenePos) self.leftMouseButtonPressed.emit(clippedCoords[0], clippedCoords[1]) # PANNING IS ALWAYS POSSIBLE WITH WHEEL BUTTON PRESSED (!) # if event.button() == Qt.MiddleButton: # self.setDragMode(QGraphicsView.ScrollHandDrag) if event.button() == Qt.RightButton: clippedCoords = self.clipScenePos(scenePos) self.rightMouseButtonPressed.emit(clippedCoords[0], clippedCoords[1]) self.clicked_x = event.pos().x() self.clicked_y = event.pos().y() QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): """Overload QGraphicsView method.""" if event.button() == Qt.LeftButton: self.scene().signal_reset_move.emit() #print "mousePressEvent, item: ", self.itemAt(event.pos()), event.pos() item_at = self.itemAt(event.pos()) if not item_at: # clicked outside any item => deselect all # note: it is much better to handle it in GraphicsView # than in Scene, because precision is better # otherwise sometimes clicking could deselect, # although the ray appeared "hovered" logger.debug("deselect all") self.scene().signal_set_all_selected.emit(False) else: logger.debug("clicked on {}".format(item_at)) # forward event QGraphicsView.mousePressEvent(self, event) elif event.button() == Qt.MiddleButton: # pan mode self._previous_transformation_anchor = self.transformationAnchor() self.setTransformationAnchor(QGraphicsView.NoAnchor) # This prevents the scrollContentsBy function of re-sending # the mouseMove events (and avoid deselections) self._previous_interactive_state = self.isInteractive() self.setInteractive(False) # store position self._previous_position = event.pos() else: # forward event QGraphicsView.mousePressEvent(self, event)
def inputGraphicsViewMousePressEvent(self, event): if event.modifiers() == QtCore.Qt.ShiftModifier: # Comment out to permit the view for sending the event to the child scene. QGraphicsView.mousePressEvent(self.inputGraphicsView, event) else: self.drawingFlag = True if not self.videoPlaybackWidget.isPlaying(): self.videoPlaybackWidget.playButtonClicked()
def mousePressEvent(self, event): sc_pos = self.mapToScene(event.pos()) if self.panSelect: self.setDragMode(QGraphicsView.ScrollHandDrag) if self.zoomSelect: self.setDragMode(QGraphicsView.RubberBandDrag) self.afterLeftClick.emit(sc_pos.x(), sc_pos.y()) QGraphicsView.mousePressEvent(self, event)
def inputGraphicsViewMousePressEvent(self, event): if event.modifiers() == QtCore.Qt.ShiftModifier: # Comment out to permit the view for sending the event to the child scene. QGraphicsView.mousePressEvent(self.inputGraphicsView, event) else: self.drawingFlag = True if not self.videoPlaybackWidget.isPlaying(): self.videoPlaybackWidget.playButtonClicked()
def mousePressEvent(self, event): if event.button() == self.fMiddleButton and not self.fCtrlDown: self.fPanning = True self.setDragMode(QGraphicsView.ScrollHandDrag) event = QMouseEvent(event.type(), event.pos(), Qt.LeftButton, Qt.LeftButton, event.modifiers()) QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): """ Start mouse pan or zoom mode. """ scenePos = self.mapToScene(event.pos()) if event.button() == Qt.LeftButton: if self.canPan: self.setDragMode(QGraphicsView.ScrollHandDrag) self.leftMouseButtonPressed.emit(scenePos.x(), scenePos.y()) QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): """ Start mouse pan or zoom mode. """ scenePos = self.mapToScene(event.pos()) if event.button() == Qt.LeftButton and self.dragCrop == False: self.dragCrop = True self.cropRectangle = QRect(scenePos.x(), scenePos.y(), 0, 0) QGraphicsView.mousePressEvent(self, event) self.updateViewer()
def mousePressEvent(self, e): logger.debug('FWView.mousePressEvent but=%d %s scene x=%.1f y=%.1f'%\ (e.button(), str(e.pos()), self.x(), self.y())) # self.__class__.__name__ self.mouse_press_event.emit(e) QGraphicsView.mousePressEvent(self, e) self.pos_click = e.pos() self.rs_center = self.scene().sceneRect().center()
def mousePressEvent(self, event): if (event.button() == self._middle_button and not QApplication.keyboardModifiers() & Qt.ControlModifier): self._panning = True self.setDragMode(QGraphicsView.ScrollHandDrag) event = QMouseEvent(event.type(), event.pos(), Qt.LeftButton, Qt.LeftButton, event.modifiers()) QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, e): #print('FWView.mousePressEvent, at point: ', e.pos() #e.globalX(), e.globalY()) #QApplication.setOverrideCursor(QCursor(Qt.ClosedHandCursor)) #Qt.SizeAllCursor))# ClosedHandCursor #self.emit(QtCore.SIGNAL('mouse_press_event(QMouseEvent)'), e) self.mouse_press_event.emit(e) QGraphicsView.mousePressEvent(self, e) self.pos_click = e.pos() self.rs_center = self.scene().sceneRect().center() self.invscalex = 1. / self.transform().m11() self.invscaley = 1. / self.transform().m22()
def mousePressEvent(self, event): if event.button() == Qt.RightButton: scenePos = self.mapToScene(event.pos()) self.rightMouseButtonPressed.emit(scenePos.x(), scenePos.y()) elif event.button() == Qt.LeftButton: self.setDragMode(QGraphicsView.ScrollHandDrag) QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): if event.button() == self.fMiddleButton and not self.fCtrlDown: self.fPanning = True self.setDragMode(QGraphicsView.ScrollHandDrag) event = QMouseEvent(event.type(), event.localPos(), event.windowPos(), event.screenPos(), Qt.LeftButton, Qt.LeftButton, event.modifiers(), Qt.MouseEventSynthesizedByApplication) QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): """Go to the next / previous image, or be able to drag the image with a hand.""" if event.button() == Qt.LeftButton: x = event.x() if x < 100: self.go_prev_img() elif x > self.width() - 100: self.go_next_img() else: self.setDragMode(QGraphicsView.ScrollHandDrag) QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): """Go to the next / previous image, or be able to drag the image with a hand.""" if event.button() == Qt.LeftButton: x = event.x() if x < 100: self.go_prev_img() elif x > self.width() - 100: self.go_next_img() else: self.setDragMode(QGraphicsView.ScrollHandDrag) QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): if self.hasImage(): """ Start drawing, panning with mouse, or zooming in """ scenePos = self.mapToScene(event.pos()) if event.button() == Qt.LeftButton: self._overlay_stack.append(self.mask_pixmap.copy()) if self.direct_mask_paint: self._offscreen_mask_stack.append( self._offscreen_mask.copy()) # If ALT is held, replace color repaint_was_active = False if QApplication.keyboardModifiers() & Qt.AltModifier: try: repaint_was_active = True self.viewport().setCursor(Qt.BusyCursor) self.repaintArea() except Exception as e: print("Cannot repaint region. Additional information:") print(e) self.viewport().setCursor(Qt.ArrowCursor) # If SHIFT is held, draw a line if QApplication.keyboardModifiers() & Qt.ShiftModifier: self.drawMarkerLine(event) # If CONTROL is held, erase, but only if global erase override is not enabled if not self.global_erase_override: if QApplication.keyboardModifiers() & Qt.ControlModifier: self.current_painting_mode = self.MODE_ERASE else: self.current_painting_mode = self.MODE_PAINT # If the user just clicks, add a marker (unless repainting was done) if not repaint_was_active: self.fillMarker(event) self.leftMouseButtonPressed.emit(scenePos.x(), scenePos.y()) elif event.button() == Qt.MiddleButton: if self.canPan: self.__prevMousePos = event.pos() self.viewport().setCursor(Qt.ClosedHandCursor) self._cursorHandle.hide() self.middleMouseButtonPressed.emit(scenePos.x(), scenePos.y()) elif event.button() == Qt.RightButton: if self.canZoom: self.setDragMode(QGraphicsView.RubberBandDrag) self._cursorHandle.hide() self.rightMouseButtonPressed.emit(scenePos.x(), scenePos.y()) QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): scenePos = self.mapToScene(event.pos()) self.mousePressLoc.emit(scenePos.x(), scenePos.y()) self.press = scenePos.toPoint() if event.button() == Qt.LeftButton: self.loc = scenePos.toPoint() if self.mode == "view": self.setDragMode(QGraphicsView.ScrollHandDrag) else: self.selLoc.emit(self.mode) elif event.button() == Qt.RightButton: self.setDragMode(QGraphicsView.RubberBandDrag) QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): """ Start mouse pan or zoom mode. """ scenePos = self.mapToScene(event.pos()) if event.button() == Qt.LeftButton: if self.canPan: self.setDragMode(QGraphicsView.ScrollHandDrag) self.leftMouseButtonPressed.emit(scenePos.x(), scenePos.y()) elif event.button() == Qt.RightButton: if self.canZoom: self.setDragMode(QGraphicsView.RubberBandDrag) self.rightMouseButtonPressed.emit(scenePos.x(), scenePos.y()) QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): # Handle pan event if event.button() == Qt.MiddleButton or \ (event.button() == Qt.LeftButton and event.modifiers() == Qt.AltModifier): if not self._hoveredNode: self._lastPanPoint = event.pos() self.setCursor(Qt.ClosedHandCursor) self._panning = True # Handle augmented selection elif event.button() == Qt.LeftButton: # Handle connection deletion if event.modifiers() == Qt.ShiftModifier: self._cutStartPosition = self.mapToScene(event.pos()) # Create visible path if self._drawPathItem is None: self._drawPathItem = self.scene().addPath(QPainterPath()) color = QColor(255, 0, 0) pen = QPen(color) self._drawPathItem.setPen(pen) self._drawPathItem.setVisible(True) self.setCursor(Qt.CrossCursor) # Select connection elif event.modifiers() == Qt.NoModifier: scene_pos = self.mapToScene(event.pos()) connection = self.findConnectionAt(scene_pos, SELECT_SIZE) # If found connection if connection is not None: for connection_ in self._connections: connection_.setActiveState(False) # Set selected connection.setActiveState(True) self._activeConnection = connection # Unselect current else: connection = self._activeConnection if connection: connection.setActiveState(False) self._activeConnection = None self.update() QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): self.click = True self.selection = True if self.selection: event_pos = self.mapToScene(event.pos()) pos = (int(event_pos.x()), int(event_pos.y())) if 0 <= pos[0] < self.scene_size[0] and 0 <= pos[ 1] < self.scene_size[1]: self.event_origin = event_pos else: self.event_origin = None self.click = True else: QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): """ Start creation of rubber band """ if event.button() == Qt.LeftButton: self.origin = event.pos() self.rubberBand.setGeometry(QRect(self.origin, QSize())) self.rubberBandScenePos = self.mapToScene(self.rubberBand.geometry()) self.rubberBand.show() self.changeRubberBand = True elif event.button() == Qt.MidButton: self.setCursor(Qt.ClosedHandCursor) self.dragPrevMousePos = event.pos() QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, e): #logger.debug('FWView.mousePressEvent, at point: ', e.pos() #e.globalX(), e.globalY()) #QApplication.setOverrideCursor(QCursor(Qt.ClosedHandCursor)) #Qt.SizeAllCursor))# ClosedHandCursor #self.emit(QtCore.SIGNAL('mouse_press_event(QMouseEvent)'), e) logger.debug('FWView.mousePressEvent but=%d %s scene x=%.1f y=%.1f'%\ (e.button(), str(e.pos()), self.x(), self.y())) # self.__class__.__name__ self.mouse_press_event.emit(e) QGraphicsView.mousePressEvent(self, e) self.pos_click = e.pos() self.rs_center = self.scene().sceneRect().center() self.invscalex = 1. / self.transform().m11() self.invscaley = 1. / self.transform().m22()
def mousePressEvent(self, event): """ Start mouse pan or zoom mode. """ self.lastMousePressSec = time.time() self.lastMousePressPos = event.pos() scenePos = self.mapToScene(event.pos()) if event.button() == Qt.LeftButton: if self.canPan: self.setDragMode(QGraphicsView.ScrollHandDrag) self.leftMouseButtonPressed.emit(scenePos.x(), scenePos.y()) elif event.button() == Qt.RightButton: if self.canZoom: self.setDragMode(QGraphicsView.RubberBandDrag) self.rightMouseButtonPressed.emit(scenePos.x(), scenePos.y()) QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): """ Start mouse pan or zoom mode. """ scene_pos = self.mapToScene(event.pos()) self.click_start_pos = event.pos() if event.button() == Qt.LeftButton: if self._t_key_pressed: self._started_tickmark_click = True self.setDragMode(QGraphicsView.RubberBandDrag) else: self.setDragMode(QGraphicsView.ScrollHandDrag) self.leftMouseButtonPressed.emit(scene_pos.x(), scene_pos.y()) elif event.button() == Qt.RightButton: self.setDragMode(QGraphicsView.RubberBandDrag) self.rightMouseButtonPressed.emit(scene_pos.x(), scene_pos.y()) QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): """Start Pan or Zoom""" # memorize current mouse position on image self.__mousePos = self.mapToScene(event.pos()) if self.hasImage(): if event.button() == Qt.LeftButton: if self.__allowZoom and event.modifiers( ) == Qt.ControlModifier: self.setDragMode(QGraphicsView.RubberBandDrag) elif self.__allowPan: self.setDragMode(QGraphicsView.ScrollHandDrag) self.leftButtonPressed.emit(self.__mousePos.x(), self.__mousePos.y()) QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): QGraphicsView.mousePressEvent(self, event) button = event.button() modifier = event.modifiers() #pan if modifier == Qt.ControlModifier and button == Qt.LeftButton: self.start_drag = event.pos() self.panning = True #initiate/show ROI selection if modifier == Qt.ShiftModifier and button == Qt.LeftButton: self.start_drag = event.pos() if self.rubberBand is None: self.rubberBand = QRubberBand(QRubberBand.Rectangle, self.viewport()) self.rubberBand.setGeometry(QRect(self.start_drag, QSize())) self.rubberBand.show()
def mousePressEvent(self, event): if event.button() & Qt.MidButton != 0: self._pan = True self._panStartX = event.x() self._panStartY = event.y() self.setCursor(Qt.ClosedHandCursor) event.accept() else: return QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): """ Start mouse pan or zoom mode. """ scenePos = self.mapToScene(event.pos()) if event.button() == Qt.LeftButton: if self.canPan: self.setDragMode(QGraphicsView.ScrollHandDrag) self.leftMouseButtonPressed.emit(scenePos.x(), scenePos.y()) print('Pixel Coords:') print('(' + str(scenePos.x()) + ',' + str(scenePos.y()) + ')') print('Pixel Intensities:') print(self.image[int(scenePos.y()), int(scenePos.x()), :]) print('\n') elif event.button() == Qt.RightButton: if self.canZoom: self.setDragMode(QGraphicsView.RubberBandDrag) self.rightMouseButtonPressed.emit(scenePos.x(), scenePos.y()) QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): modifiers = QApplication.keyboardModifiers() if modifiers == QtCore.Qt.ShiftModifier: # Show rubber band self.rubber_band_origin = event.pos() self.rubber_band.setGeometry( QRect(self.rubber_band_origin, QSize())) self.rubber_band.show() self.rubber_band_changable = True # Show selection rect position if self.show_info: scene_pos = self.mapToScene( event.pos()) # convert to scene position x_scene, y_scene = scene_pos.x(), scene_pos.y() self.show_rect_position(x_scene, y_scene, x_scene, y_scene) else: QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): """ Start mouse pan or zoom mode. """ if self.npImage is not None: if event.button() == Qt.LeftButton: scenePos = self.mapToScene(event.pos()) if self.togglePanZoom: self.setDragMode(QGraphicsView.RubberBandDrag) else: self.setDragMode(QGraphicsView.ScrollHandDrag) #self.rightMouseButtonPressed.emit(scenePos.x(), #scenePos.y()) self.leftMouseButtonPressed.emit(scenePos.x(), scenePos.y()) elif event.button() == Qt.RightButton: self.__rightMouseDown = True self.__WLDownPos = event.pos() QGraphicsView.mousePressEvent(self, event)
def mousePressEvent(self, event): """docstring for mousePressEvent""" if self._transform_enable == True and qApp.keyboardModifiers(): which_buttons = event.buttons() if which_buttons in [self._button_pan, self._button_pan_alt]: self._panEnable() posf = event.localPos() self._x0 = posf.x() self._y0 = posf.y() elif which_buttons == self._button_zoom: self._dolly_zoom_enable = True self._last_scale_factor = 0 # QMouseEvent.y() returns the position of the mouse cursor # relative to the widget self._y0 = event.localPos().y() else: QGraphicsView.mousePressEvent(self, event) else: QGraphicsView.mousePressEvent(self, event)