diff options
-rw-r--r-- | line.py | 24 |
1 files changed, 18 insertions, 6 deletions
@@ -1,4 +1,4 @@ -from PyQt5.QtGui import QFont, QPen +from PyQt5.QtGui import QFont, QPen, QPainterPath from PyQt5.QtWidgets import QGraphicsLineItem, QLineEdit, QGraphicsProxyWidget, QGraphicsItem from PyQt5.QtCore import Qt, QPointF, QRectF @@ -22,17 +22,29 @@ class Line(QGraphicsItem): def setEndGripItem(self, item): self.endGripItem = item + def shape(self): + x0, y0 = self.startPoint.x(), self.startPoint.y() + x1, y1 = self.endPoint.x(), self.endPoint.y() + path = QPainterPath(QPointF(x0,y0)) + path.lineTo((x0 + x1) / 2, y0) + path.moveTo((x0 + x1) / 2, y0) + path.lineTo((x0 + x1) / 2, y1) + path.moveTo((x0 + x1) / 2, y1) + path.lineTo(x1, y1) + return path + def boundingRect(self): x0, y0 = self.startPoint.x(), self.startPoint.y() x1, y1 = self.endPoint.x(), self.endPoint.y() return QRectF(min(x0, x1), min(y0, y1), abs(x1 - x0), abs(y1 - y0)) def paint(self, painter, style, widget=None): - x0, y0 = self.startPoint.x(), self.startPoint.y() - x1, y1 = self.endPoint.x(), self.endPoint.y() - painter.drawLine(x0, y0, (x0 + x1) / 2, y0) - painter.drawLine((x0 + x1) / 2, y0, (x0 + x1) / 2, y1) - painter.drawLine((x0 + x1) / 2, y1, x1, y1) + # x0, y0 = self.startPoint.x(), self.startPoint.y() + # x1, y1 = self.endPoint.x(), self.endPoint.y() + # painter.drawLine(x0, y0, (x0 + x1) / 2, y0) + # painter.drawLine((x0 + x1) / 2, y0, (x0 + x1) / 2, y1) + # painter.drawLine((x0 + x1) / 2, y1, x1, y1) + painter.drawPath(self.shape()) def updateLine(self, startPoint=None, endPoint=None): |