def mouseMoveEvent(self, event: QMouseEvent) -> None: if event.x() > 0 and event.y() > 0 and event.x() <= self.width() and event.y() <= self.height(): # IF DRAWING IS NOT JUST A MERE POINT... if len(self.strokeT[-1]) == 1: self.timing.restart() self.paused += 1 self.strokeX[-1].append(event.x()) self.strokeY[-1].append(event.y()) self.strokeT[-1].append(self.timing.elapsed() + self.paused) else: return return super().mouseMoveEvent(event)
def mousePressEvent(self, event: QMouseEvent): """ Event: Don't Invoke This Method Manually """ self.setFocus(Qt.FocusReason.MouseFocusReason) if event.button() == Qt.MouseButton.LeftButton: # -> Store Last Rect's X,Y Pos; self.__sRect_last_xy = self.__sRect.topLeft() """```````````````````````````````````````""" if self.getMoveHandle.contains(event.x(), event.y()): self.__is_move_enable = True # self.setCursor( Qt.SizeAllCursor ) elif self.getResizeHandle.contains(event.x(), event.y()): self.__is_resize_enable = True # self.setCursor( Qt.SizeFDiagCursor ) else: self.__is_selection_enabled = True self.__sRect.setTopLeft(event.pos())
def mouseReleaseEvent(self, event_data: QMouseEvent): if self._ignoring_mouse_events: return if 0 <= event_data.x() <= self.width() and 0 <= event_data.y( ) <= self.height(): event_data.accept() self.set_checked(not self.is_checked)
def mousePressEvent(self, event: QtGui.QMouseEvent): pos_real = self.convert_to_real((event.x(), event.y())) draw_image = ImageDraw.ImageDraw(self._working_image) draw_image.point(pos_real, (255, 0, 0, 255)) print('Mouse press %s:%s' % pos_real) self.update()
def mousePressEvent(self, event: QMouseEvent) -> None: self.timing.restart() self.strokeX.append(list()) self.strokeY.append(list()) self.strokeT.append(list()) self.strokeX[-1].append(event.x()) self.strokeY[-1].append(event.y()) self.strokeT[-1].append(self.paused) return super().mousePressEvent(event)
def mouseReleaseEvent(self, event: gui.QMouseEvent): if event.button() != core.Qt.LeftButton: event.ignore() return event.accept() progress = event.x() / self.width() self.setValue(int(progress * self.maximum())) if self._on_click: self._on_click(event)
def mouseMoveEvent(self, event: QMouseEvent): super().mouseMoveEvent(event) if self.__current_rgb_mat is not None: x = event.x() y = event.y() h, w, _ = self.__current_rgb_mat.shape if x < w and y < h: self.position_info.emit(MatViewPosInfo(x, y, red=self.__current_rgb_mat[y][x][0], green=self.__current_rgb_mat[y][x][1], blue=self.__current_rgb_mat[y][x][2]))
def mouseMoveEvent(self, event: QMouseEvent): """ Event: Don't Invoke This Method Manually """ mpos = event.pos() # Mouse Position if self.__is_selection_enabled or self.__is_resize_enable: # Prevent Selection From Outside Canvas; if mpos.x() > self.width(): mpos.setX(self.width()) if mpos.y() > self.height(): mpos.setY(self.height()) if not self.__ratio: # -> Set Selection Rect's End Position; self.__sRect.setBottomRight(mpos) else: # -> Calclulate & Apply Ratio; #-----------[ Can Be Improve ]-----------# width_as_ratio = round(self.__sRect.height() * self.__ratio) # Ratio Appled; self.__sRect.setWidth(width_as_ratio) self.__sRect.setBottom(mpos.y()) elif self.__is_move_enable: # -> Move Selection Rect; rectRef = QRect(self.__sRect) rectRef.moveCenter(mpos) if rectRef.x() < 0 or rectRef.right() > self.width(): mpos.setX(self.__sRect.center().x()) if rectRef.y() < 0 or rectRef.bottom() > self.height(): mpos.setY(self.__sRect.center().y()) self.__sRect.moveCenter(mpos) """``````````````````````````````````````````````````""" # -> Cursor Pointer Logic; if self.getResizeHandle.contains(event.x(), event.y()): self.setCursor(Qt.SizeFDiagCursor) elif self.getMoveHandle.contains(event.x(), event.y()): self.setCursor(Qt.SizeAllCursor) else: self.setCursor(Qt.ArrowCursor) # -> Update Widget; self.update()
def mouseReleaseEvent(self, event: QMouseEvent): if self.rubberBand is not None: self.rubberBand.hide() self.close() time.sleep(0.6) rect = (min(self.origin.x(), event.x()), min(self.origin.y(), event.y()), abs(event.x() - self.origin.x()), abs(event.y() - self.origin.y())) screenShot = self.screen.grabWindow(QApplication.desktop().winId(), *rect) self.scrotFinished.emit(screenShot)
def mousePressEvent(self, mouseevent: QMouseEvent): super().mouseMoveEvent(mouseevent) if mouseevent.button() == Qt.LeftButton: x = mouseevent.x() y = mouseevent.y() h = (np.arctan2(x - self.radius, y - self.radius) + np.pi) / (2. * np.pi) s = np.sqrt(np.power(x - self.radius, 2) + np.power(y - self.radius, 2)) / self.radius v = 1.0 if s < 1.0: self.qc_Color.setHsvF(h, s, v, 1.0)
def mouseReleaseEvent(self, event: QMouseEvent): """ Event: Don't Invoke This Method Manually """ if event.button() == Qt.MouseButton.LeftButton: self.__is_selection_enabled = False self.__is_resize_enable = False self.__is_move_enable = False # -> Resotre Cursor; # self.setCursor( Qt.ArrowCursor ) """`````````````````````````````````````""" mouse_moved_amount_x = self.__sRect.x() - event.x() mouse_moved_amount_y = self.__sRect.y() - event.y() if mouse_moved_amount_x == 0 or mouse_moved_amount_y == 0: # -> Restore sRect's X,Y Position; self.__sRect.setTopLeft(self.__sRect_last_xy)
def mousePressEvent(self, event: QMouseEvent): self.isPressed = True self.mousePos = event.x(), event.y() if event.buttons() & Qt.MiddleButton: for i, w in enumerate(self.interestings[::-1]): if not w.isVisible(): del self.interestings[i] print(len(self.interestings)) t = Interesting() t.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.CustomizeWindowHint) t.setWindowTitle("lucifer") t.show() self.interestings.append(t)
def mousePressEvent(self, event: QMouseEvent): self.isPressed = True self.mousePos = event.x(), event.y()
def mouseMoveEvent(self, event: QtGui.QMouseEvent): if(self._pressed): x, y = event.x(), event.y() self.hotspot = x, y self.userHotspotChange.emit(x, y)
def mouseMoveEvent(self, event: QtGui.QMouseEvent): self.moveSlider(event.x())
def mousePressEvent(self, event: QtGui.QMouseEvent): if event.button() == QtCore.Qt.LeftButton: self.moveSlider(event.x()) event.accept() else: QtWidgets.QWidget.mousePressEvent(event)
def mouseMoveEvent(self, event: QMouseEvent): self._update_value_by_x(event.x()) event.accept()
def mouseMoveEvent(self, event: QMouseEvent): """ :type event: QMouseEvent :param event: :return: """ self.mousePoint = QPoint(event.globalPos().x(), event.globalPos().y()) if self.action is None: self.action = ACTION_SELECT if not self.mousePressed: point = QPoint(event.x(), event.y()) self.detect_mouse_position(point) self.setCursorStyle() self.redraw() else: self.endX, self.endY = event.x(), event.y() # if self.mousePosition != OUTSIDE_AREA: # self.action = ACTION_MOVE_SELECTED if self.action == ACTION_SELECT: self.selected_area.setBottomRight(QPoint(event.x(), event.y())) self.redraw() elif self.action == ACTION_MOVE_SELECTED: self.selected_area = QRect(self.selectedAreaRaw) if self.mousePosition == MousePosition.INSIDE_AREA: move_to_x = event.x( ) - self.startX + self.selected_area.left() move_to_y = event.y( ) - self.startY + self.selected_area.top() if 0 <= move_to_x <= self.screenPixel.width( ) - 1 - self.selected_area.width(): self.selected_area.moveLeft(move_to_x) if 0 <= move_to_y <= self.screenPixel.height( ) - 1 - self.selected_area.height(): self.selected_area.moveTop(move_to_y) self.selected_area = self.selected_area.normalized() self.selectedAreaRaw = QRect(self.selected_area) self.startX, self.startY = event.x(), event.y() self.redraw() elif self.mousePosition == MousePosition.ON_THE_LEFT_SIDE: move_to_x = event.x( ) - self.startX + self.selected_area.left() if move_to_x <= self.selected_area.right(): self.selected_area.setLeft(move_to_x) self.selected_area = self.selected_area.normalized() self.redraw() elif self.mousePosition == MousePosition.ON_THE_RIGHT_SIDE: move_to_x = event.x( ) - self.startX + self.selected_area.right() self.selected_area.setRight(move_to_x) self.selected_area = self.selected_area.normalized() self.redraw() elif self.mousePosition == MousePosition.ON_THE_UP_SIDE: move_to_y = event.y( ) - self.startY + self.selected_area.top() self.selected_area.setTop(move_to_y) self.selected_area = self.selected_area.normalized() self.redraw() elif self.mousePosition == MousePosition.ON_THE_DOWN_SIDE: move_to_y = event.y( ) - self.startY + self.selected_area.bottom() self.selected_area.setBottom(move_to_y) self.selected_area = self.selected_area.normalized() self.redraw() elif self.mousePosition == MousePosition.ON_THE_TOP_LEFT_CORNER: move_to_x = event.x( ) - self.startX + self.selected_area.left() move_to_y = event.y( ) - self.startY + self.selected_area.top() self.selected_area.setTopLeft(QPoint(move_to_x, move_to_y)) self.selected_area = self.selected_area.normalized() self.redraw() elif self.mousePosition == MousePosition.ON_THE_BOTTOM_RIGHT_CORNER: move_to_x = event.x( ) - self.startX + self.selected_area.right() move_to_y = event.y( ) - self.startY + self.selected_area.bottom() self.selected_area.setBottomRight( QPoint(move_to_x, move_to_y)) self.selected_area = self.selected_area.normalized() self.redraw() elif self.mousePosition == MousePosition.ON_THE_TOP_RIGHT_CORNER: move_to_x = event.x( ) - self.startX + self.selected_area.right() move_to_y = event.y( ) - self.startY + self.selected_area.top() self.selected_area.setTopRight(QPoint( move_to_x, move_to_y)) self.selected_area = self.selected_area.normalized() self.redraw() elif self.mousePosition == MousePosition.ON_THE_BOTTOM_LEFT_CORNER: move_to_x = event.x( ) - self.startX + self.selected_area.left() move_to_y = event.y( ) - self.startY + self.selected_area.bottom() self.selected_area.setBottomLeft( QPoint(move_to_x, move_to_y)) self.redraw() else: pass elif self.action == ACTION_RECT: self.drawRect(self.startX, self.startY, event.x(), event.y(), False) self.redraw() pass elif self.action == ACTION_ELLIPSE: self.drawEllipse(self.startX, self.startY, event.x(), event.y(), False) self.redraw() elif self.action == ACTION_ARROW: self.drawArrow(self.startX, self.startY, event.x(), event.y(), False) self.redraw() elif self.action == ACTION_LINE: self.drawLine(self.startX, self.startY, event.x(), event.y(), False) self.redraw() elif self.action == ACTION_FREEPEN: y1, y2 = event.x(), event.y() rect = self.selected_area.normalized() if y1 <= rect.left(): y1 = rect.left() elif y1 >= rect.right(): y1 = rect.right() if y2 <= rect.top(): y2 = rect.top() elif y2 >= rect.bottom(): y2 = rect.bottom() self.pointPath.lineTo(y1, y2) self.drawFreeLine(self.pointPath, False) self.redraw()
def mouseMoveEvent(self, event: QtGui.QMouseEvent): if (self._pressed): self._hotspot_preview_loc = (event.x(), event.y()) self.update()
def mousePressEvent(self, event: QMouseEvent): self.colorDefaultLabels() self.redClickedTransistor(event.x(), event.y())
def mouseMoveEvent(self, event: QMouseEvent): self.mouse_move.emit(event.x(), event.y())
def mousePressEvent(self, event: QMouseEvent): self.set_focus() self._update_value_by_x(event.x()) event.accept()
def mousePressEvent(self, event: QtGui.QMouseEvent): self._pressed = True self._hotspot_preview_loc = (event.x(), event.y()) self.update()
def mousePressEvent(self, event: QMouseEvent): progress = event.x() / self.width() value = int(progress * self.maximum()) self.setValue(value)
def mousePressEvent(self, ev: QtGui.QMouseEvent) -> None: ev.button() == QtCore.Qt.LeftButton and self.setValue( self.minimum() + (self.maximum() - self.minimum()) * ev.x() // self.width()) super().mousePressEvent(ev)
def mouseMoveEvent(self, e: QtGui.QMouseEvent): QWidget.mouseMoveEvent(self, e) if not self.m_isEditing: return if not self.m_infocus: return if not e.buttons() and QtCore.Qt.LeftButton: p = QPoint(e.x() + self.geometry().x(), e.y() + self.geometry().y()) self.setCursorShape(p) return if (self.mode == Mode.MOVE or self.mode == Mode.NONE) and e.buttons() and QtCore.Qt.LeftButton: toMove = e.globalPos() - self.position if toMove.x() < 0: return if toMove.y() < 0: return if toMove.x() > self.parentWidget().width() - self.width(): return self.move(toMove) self.newGeometry.emit(self.geometry()) self.parentWidget().repaint() return if (self.mode != Mode.MOVE) and e.buttons() and QtCore.Qt.LeftButton: if self.mode == Mode.RESIZETL: # Left - Top newwidth = e.globalX() - self.position.x() - self.geometry().x( ) newheight = e.globalY() - self.position.y() - self.geometry( ).y() toMove = e.globalPos() - self.position self.resize(self.geometry().width() - newwidth, self.geometry().height() - newheight) self.move(toMove.x(), toMove.y()) elif self.mode == Mode.RESIZETR: # Right - Top newheight = e.globalY() - self.position.y() - self.geometry( ).y() toMove = e.globalPos() - self.position self.resize(e.x(), self.geometry().height() - newheight) self.move(self.x(), toMove.y()) elif self.mode == Mode.RESIZEBL: # Left - Bottom newwidth = e.globalX() - self.position.x() - self.geometry().x( ) toMove = e.globalPos() - self.position self.resize(self.geometry().width() - newwidth, e.y()) self.move(toMove.x(), self.y()) elif self.mode == Mode.RESIZEB: # Bottom self.resize(self.width(), e.y()) elif self.mode == Mode.RESIZEL: # Left newwidth = e.globalX() - self.position.x() - self.geometry().x( ) toMove = e.globalPos() - self.position self.resize(self.geometry().width() - newwidth, self.height()) self.move(toMove.x(), self.y()) elif self.mode == Mode.RESIZET: # Top newheight = e.globalY() - self.position.y() - self.geometry( ).y() toMove = e.globalPos() - self.position self.resize(self.width(), self.geometry().height() - newheight) self.move(self.x(), toMove.y()) elif self.mode == Mode.RESIZER: # Right self.resize(e.x(), self.height()) elif self.mode == Mode.RESIZEBR: # Right - Bottom self.resize(e.x(), e.y()) self.parentWidget().repaint() self.newGeometry.emit(self.geometry()) # class MainWindow(QMainWindow): # def __init__(self): # super().__init__() # self.showMaximized() # lab1 = QLabel("Label1") # lab2 = QLabel("Label2") # con1 = TContainer(self, QPoint(10,10), lab1) # con2 = TContainer(self, QPoint(20,50), lab2) # if __name__ == '__main__': # app = QApplication(sys.argv) # ex = MainWindow() # sys.exit(app.exec_())