Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] plotutils: Fix scene layout tracking in AnchorItem #6859

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading