diff --git a/Orange/widgets/visualize/utils/plotutils.py b/Orange/widgets/visualize/utils/plotutils.py index e92ab787af1..08b9fcbe73b 100644 --- a/Orange/widgets/visualize/utils/plotutils.py +++ b/Orange/widgets/visualize/utils/plotutils.py @@ -11,7 +11,7 @@ QFont, QPalette from AnyQt.QtWidgets import ( QGraphicsLineItem, QGraphicsSceneMouseEvent, QPinchGesture, - QGraphicsItemGroup, QWidget + QGraphicsItemGroup, QWidget, QGraphicsWidget ) import pyqtgraph as pg @@ -39,7 +39,8 @@ class AnchorItem(pg.GraphicsWidget): def __init__(self, parent=None, line=QLineF(), text="", **kwargs): super().__init__(parent, **kwargs) self._text = text - self.setFlag(pg.GraphicsObject.ItemHasNoContents) + self.setFlag(QGraphicsWidget.ItemSendsScenePositionChanges) + self.setFlag(QGraphicsWidget.ItemHasNoContents) self._spine = QGraphicsLineItem(line, self) angle = line.angle() @@ -57,6 +58,8 @@ def __init__(self, parent=None, line=QLineF(), text="", **kwargs): if parent is not None: self.setParentItem(parent) + self.__updateLayout() + def get_xy(self): point = self._spine.line().p2() return point.x(), point.y() @@ -131,6 +134,18 @@ def changeEvent(self, event): self._label.setColor(self.palette().color(QPalette.Text)) super().changeEvent(event) + def itemChange(self, change, value): + if change in ( + QGraphicsWidget.ItemParentHasChanged, + QGraphicsWidget.ItemSceneHasChanged, + # ItemScenePositionHasChanged seems to trigger for any scene + # transform change (even if the pos has not actually changed). + # Das ist gut. + QGraphicsWidget.ItemScenePositionHasChanged, + ): + self.__updateLayout() + return super().itemChange(change, value) + class HelpEventDelegate(QObject): def __init__(self, delegate, parent=None):