From bcceca62804d60c6308c6cefb3a65a9b074ee773 Mon Sep 17 00:00:00 2001 From: sumit Date: Thu, 30 Apr 2020 10:55:15 +0530 Subject: change area of mouse interaction to line --- line.py | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'line.py') diff --git a/line.py b/line.py index 941016d..d8e5487 100644 --- a/line.py +++ b/line.py @@ -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): -- cgit