def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent): super(QGraphicsBlockItem, self).mouseMoveEvent(event) self.setPos(event.scenePos() - event.buttonDownPos(Qt.MouseButton.LeftButton)) self.c, self.cS = self.closestItem() imgPosibleConnectH = self.scene().imgPosibleConnectH imgPosibleConnectV = self.scene().imgPosibleConnectV if self.c is not None: if self.c.type is ConnectionType.TOP: imgPosibleConnectH.setPos(self.c.parent.pos()) imgPosibleConnectH.setVisible(True) imgPosibleConnectH.setZValue(1) elif self.c.type is ConnectionType.BOTTOM: imgPosibleConnectH.setPos(self.c.parent.pos() + QPointF(0, self.c.parent.pixmap().height() - 5)) imgPosibleConnectH.setVisible(True) imgPosibleConnectH.setZValue(1) elif self.c.type is ConnectionType.RIGHT: imgPosibleConnectV.setPos( self.c.parent.pos() + QPointF(self.c.parent.pixmap().width() - 5, 0) + QPointF(0, 5)) imgPosibleConnectV.setVisible(True) imgPosibleConnectV.setZValue(1) elif self.c.type is ConnectionType.LEFT: imgPosibleConnectV.setPos(self.c.parent.pos() + QPointF(0, 5)) imgPosibleConnectV.setVisible(True) imgPosibleConnectV.setZValue(1) elif self.c.type is ConnectionType.BOTTOMIN: imgPosibleConnectH.setPos(self.c.parent.pos() + QPointF(16, 38)) imgPosibleConnectH.setVisible(True) imgPosibleConnectH.setZValue(1) else: imgPosibleConnectH.setVisible(False) imgPosibleConnectV.setVisible(False)
def mouseMoveEvent(self, event: QGraphicsSceneMouseEvent): box = QRectF(self.buttonDownRect) pos = event.pos() offset = pos - event.buttonDownPos(Qt.LeftButton) if self.handleSelected is None: box.translate(offset) new_box = box elif self.handleSelected == 0: pos = box.topLeft() + offset new_size = box.bottomRight() - pos width = max(new_size.x(), 0) height = max(new_size.y(), 0) left = min(pos.x(), box.right()) top = min(pos.y(), box.bottom()) new_box = QRectF(left, top, width, height) elif self.handleSelected == 1: pos = box.topLeft() + offset height = max(box.bottom() - pos.y(), 0) top = min(pos.y(), box.bottom()) new_box = QRectF(box.left(), top, box.width(), height) elif self.handleSelected == 2: pos = box.topRight() + offset top = min(pos.y(), box.bottom()) width = max(pos.x() - box.left(), 0) height = max(box.bottom() - pos.y(), 0) new_box = QRectF(box.left(), top, width, height) elif self.handleSelected == 3: pos = box.topRight() + offset width = max(pos.x() - box.left(), 0) new_box = QRectF(box.left(), box.top(), width, box.height()) elif self.handleSelected == 4: pos = box.bottomRight() + offset new_size = pos - box.topLeft() width = max(new_size.x(), 0) height = max(new_size.y(), 0) new_box = QRectF(box.left(), box.top(), width, height) elif self.handleSelected == 5: pos = box.bottomRight() + offset height = max(pos.y() - box.top(), 0) new_box = QRectF(box.left(), box.top(), box.width(), height) elif self.handleSelected == 6: pos = box.bottomLeft() + offset left = min(pos.x(), box.right()) width = max(box.right() - pos.x(), 0) height = max(pos.y() - box.top(), 0) new_box = QRectF(left, box.top(), width, height) elif self.handleSelected == 7: pos = box.bottomLeft() + offset left = min(pos.x(), box.right()) width = max(box.right() - pos.x(), 0) new_box = QRectF(left, box.top(), width, box.height()) new_box = QRectF(round(new_box.left()), round(new_box.top()), round(new_box.width()), round(new_box.height())) self.setRect(new_box) self.setHandlesPos() self.signalHandler.boxChanged.emit(self.tabIndex, self.rowIndex, new_box)