small TargetItem fixes (#1715)

* angle is just an int, not a method

* more TargetItem use in the example

* offset is needed before super sometimes

* use setLabel, too
This commit is contained in:
Martin Chase 2021-04-14 10:44:03 -07:00 committed by GitHub
parent dfa225f56f
commit a465f93d9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 18 deletions

View File

@ -32,33 +32,29 @@ p1.addItem(inf1)
p1.addItem(inf2)
p1.addItem(inf3)
targetItem1 = pg.TargetItem(
label=True,
symbol="crosshair",
labelOpts={
"angle": 0
}
)
targetItem1 = pg.TargetItem()
targetItem2 = pg.TargetItem(
pos=(30, 5),
size=20,
label="vert={1:0.2f}",
symbol="star",
pen="#F4511E",
label="vert={1:0.2f}",
labelOpts={
"angle": 45,
"offset": QtCore.QPoint(15, 15)
}
)
targetItem2.label().setAngle(45)
targetItem3 = pg.TargetItem(
pos=(10, 10),
size=10,
label="Third Label",
symbol="x",
symbol="x",
pen="#00ACC1",
labelOpts={
)
targetItem3.setLabel(
"Third Label",
{
"anchor": QtCore.QPointF(0.5, 0.5),
"offset": QtCore.QPointF(30, 0),
"color": "#558B2F",
@ -66,6 +62,7 @@ targetItem3 = pg.TargetItem(
}
)
def callableFunction(x, y):
return f"Square Values: ({x**2:.4f}, {y**2:.4f})"

View File

@ -354,7 +354,7 @@ class TargetItem(UIGraphicsItem):
DeprecationWarning,
stacklevel=2,
)
if self.label() is not None and angle != self.label().angle():
if self.label() is not None and angle != self.label().angle:
self.label().setAngle(angle)
return None
@ -393,11 +393,6 @@ class TargetLabel(TextItem):
anchor=(0, 0.5),
**kwargs,
):
super().__init__(anchor=anchor, **kwargs)
self.setParentItem(target)
self.target = target
self.setFormat(text)
if isinstance(offset, Point):
self.offset = offset
elif isinstance(offset, (tuple, list)):
@ -406,6 +401,12 @@ class TargetLabel(TextItem):
self.offset = Point(offset.x(), offset.y())
else:
raise TypeError("Offset parameter is the wrong data type")
super().__init__(anchor=anchor, **kwargs)
self.setParentItem(target)
self.target = target
self.setFormat(text)
self.target.sigPositionChanged.connect(self.valueChanged)
self.valueChanged()