我想动态旋转TextItem,但无法使其正常工作。使用setPos和setAnchor更改位置或锚定会更新项目,但要使用setAngle更改angel不会更新文本。最奇怪的是,一旦我拖动画布,它就会更新。
from pyqtgraph.Qt import QtCore, QtGui
import pyqtgraph as pg
app = QtGui.QApplication([])
w = pg.GraphicsView()
w.show()
w.resize(800,800)
view = pg.ViewBox()
w.setCentralItem(view)
view.setAspectLocked(True)
view.setRange(QtCore.QRectF(0, 0, 200, 200))
anchor = pg.TextItem()
anchor.setText("hey")
anchor.setColor(QtGui.QColor(255, 255, 255))
view.addItem(anchor)
def rotate():
x, y = anchor.pos()
anchor.setPos(x + 1, y + 1)
anchor.setAngle(anchor.angle + 10)
timer = QtCore.QTimer()
timer.timeout.connect(rotate)
timer.start(1000)
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
我想知道要调用什么信号或函数,以便该项目立即更新。