diff options
author | sumit | 2020-06-05 10:42:05 +0530 |
---|---|---|
committer | sumit | 2020-06-05 10:42:05 +0530 |
commit | 8b3337c29d33cd4fe9fb4d3f1796daa4b623616a (patch) | |
tree | 95df62c7e80624c1ffcfcd246daff063925a7927 /src/main/python/shapes | |
parent | 3685cf35417bb90b01824a07c8c6d4d8721a97a5 (diff) | |
download | Chemical-PFD-8b3337c29d33cd4fe9fb4d3f1796daa4b623616a.tar.gz Chemical-PFD-8b3337c29d33cd4fe9fb4d3f1796daa4b623616a.tar.bz2 Chemical-PFD-8b3337c29d33cd4fe9fb4d3f1796daa4b623616a.zip |
add text label for svg item
Diffstat (limited to 'src/main/python/shapes')
-rw-r--r-- | src/main/python/shapes/shapes.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/main/python/shapes/shapes.py b/src/main/python/shapes/shapes.py index 47d9a52..722b836 100644 --- a/src/main/python/shapes/shapes.py +++ b/src/main/python/shapes/shapes.py @@ -7,13 +7,23 @@ from PyQt5.QtSvg import QGraphicsSvgItem, QSvgRenderer from PyQt5.QtWidgets import (QGraphicsColorizeEffect, QGraphicsEllipseItem, QGraphicsItem, QGraphicsPathItem, QGraphicsProxyWidget, QGraphicsSceneHoverEvent, - QLineEdit) + QLineEdit, QMenu, QGraphicsTextItem) from .line import Line from utils.app import fileImporter from utils.app import fileImporter +class ItemLabel(QGraphicsTextItem): + def __init__(self, pos, parent=None): + super().__init__(parent=parent) + self.setPlainText("abc") + self.setTextInteractionFlags(Qt.TextEditorInteraction) + self.setFlags(QGraphicsItem.ItemIsMovable | + QGraphicsItem.ItemIsSelectable | + QGraphicsItem.ItemIsFocusable) + self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True) + class GripItem(QGraphicsPathItem): """ Extends QGraphicsPathItem to create the structure of the Grabbable points for resizing shapes and connecting lines. @@ -306,6 +316,7 @@ class NodeItem(QGraphicsSvgItem): # grip items connected to this item self.lineGripItems = [] self.sizeGripItems = [] + self.label =None def boundingRect(self): """Overrides QGraphicsSvgItem's boundingRect() virtual public function and @@ -455,6 +466,16 @@ class NodeItem(QGraphicsSvgItem): item.setPen(QPen(Qt.transparent)) item.setBrush(Qt.transparent) + def contextMenuEvent(self, event): + """Pop up menu + :return: + """ + contextMenu = QMenu() + addLableAction = contextMenu.addAction("add Label") + # addLableAction.triggered.connect(self.addLabel) + action = contextMenu.exec_(event.screenPos()) + if action == addLableAction: + self.label = ItemLabel(event.scenePos(), self) # classes of pfd-symbols class AirBlownCooler(NodeItem): |