Skip to content

Commit

Permalink
plotutils: Fix scene layout tracking in AnchorItem
Browse files Browse the repository at this point in the history
Since 384f6f4 the AnchorItem does not properly update its layout
due to difference in pg.GraphicsObject/pg.GraphicsWidget
implementations.
  • Loading branch information
ales-erjavec committed Jul 22, 2024
1 parent 70ebf27 commit c275a4a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions Orange/widgets/visualize/utils/plotutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
QFont, QPalette
from AnyQt.QtWidgets import (
QGraphicsLineItem, QGraphicsSceneMouseEvent, QPinchGesture,
QGraphicsItemGroup, QWidget
QGraphicsItemGroup, QWidget, QGraphicsWidget
)

import pyqtgraph as pg
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit c275a4a

Please sign in to comment.