Always update transform when setting angle of a TextItem (#970)
* Always update transform when setting angle of a TextItem * Add test to check TextItem.setAngle * Relax test a bit but still check that setAngle has an effect * Add docstring to setAngle * Remove unneeded numpy testing function imports
This commit is contained in:
parent
fc9768be3c
commit
c94b1cb99e
@ -110,9 +110,16 @@ class TextItem(GraphicsObject):
|
||||
self.updateTextPos()
|
||||
|
||||
def setAngle(self, angle):
|
||||
"""
|
||||
Set the angle of the text in degrees.
|
||||
|
||||
This sets the rotation angle of the text as a whole, measured
|
||||
counter-clockwise from the x axis of the parent. Note that this rotation
|
||||
angle does not depend on horizontal/vertical scaling of the parent.
|
||||
"""
|
||||
self.angle = angle
|
||||
self.updateTransform()
|
||||
|
||||
self.updateTransform(force=True)
|
||||
|
||||
def setAnchor(self, anchor):
|
||||
self.anchor = Point(anchor)
|
||||
self.updateTextPos()
|
||||
@ -169,7 +176,7 @@ class TextItem(GraphicsObject):
|
||||
p.setRenderHint(p.Antialiasing, True)
|
||||
p.drawPolygon(self.textItem.mapToParent(self.textItem.boundingRect()))
|
||||
|
||||
def updateTransform(self):
|
||||
def updateTransform(self, force=False):
|
||||
# update transform such that this item has the correct orientation
|
||||
# and scaling relative to the scene, but inherits its position from its
|
||||
# parent.
|
||||
@ -181,7 +188,7 @@ class TextItem(GraphicsObject):
|
||||
else:
|
||||
pt = p.sceneTransform()
|
||||
|
||||
if pt == self._lastTransform:
|
||||
if not force and pt == self._lastTransform:
|
||||
return
|
||||
|
||||
t = pt.inverted()[0]
|
||||
|
23
pyqtgraph/graphicsItems/tests/test_TextItem.py
Normal file
23
pyqtgraph/graphicsItems/tests/test_TextItem.py
Normal file
@ -0,0 +1,23 @@
|
||||
import pytest
|
||||
import pyqtgraph as pg
|
||||
|
||||
app = pg.mkQApp()
|
||||
|
||||
|
||||
def test_TextItem_setAngle():
|
||||
plt = pg.plot()
|
||||
plt.setXRange(-10, 10)
|
||||
plt.setYRange(-20, 20)
|
||||
item = pg.TextItem(text="test")
|
||||
plt.addItem(item)
|
||||
|
||||
t1 = item.transform()
|
||||
|
||||
item.setAngle(30)
|
||||
app.processEvents()
|
||||
|
||||
t2 = item.transform()
|
||||
|
||||
assert t1 != t2
|
||||
assert not t1.isRotating()
|
||||
assert t2.isRotating()
|
Loading…
Reference in New Issue
Block a user