Skip to content

Commit

Permalink
Merge pull request biolab#6859 from ales-erjavec/fixes/owfreeviz-anch…
Browse files Browse the repository at this point in the history
…or-item-transform

[FIX] plotutils: Fix scene layout tracking in AnchorItem
  • Loading branch information
markotoplak authored Oct 9, 2024
2 parents b0acfd2 + c275a4a commit 742922e
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 742922e

Please sign in to comment.