我正在使用pyqtgraph
并尝试恢复添加到给定图形中的TextItem
类对象的属性。你知道吗
虽然看起来这是一个简单的任务,但我不知道如何提取它,而且documentation也没有多大帮助。你知道吗
下面是一个片段:
import sys
from PyQt5.QtWidgets import QApplication, QWidget
import pyqtgraph as pg
import numpy as np
def refreshScreen(AnnotationsList):
for i in range(len(AnnotationsList)):
c = AnnotationsList[i]
# Now I need to extract information from the annotations:
x = c.x()
print(x)
y = c.y()
print(y)
text = c.text()
print(text)
OtherProperties = c.getProperty()
print(OtherProperties)
if __name__ == '__main__':
app = QApplication(sys.argv)
w = QWidget()
w.resize(250, 150)
w.move(300, 300)
w.setWindowTitle('Simple')
w.show()
AnnotationsList = []
c = pg.TextItem(anchor=(0,0), border=pg.mkPen(200, 200, 200))
c.setText(text='my_annotation', color=(0,0,0))
# coordinates for annotation
x = 5
y = 10
c.setPos(x,y)
AnnotationsList = np.append(AnnotationsList, c)
refreshScreen(AnnotationsList)
sys.exit(app.exec_())
我猜到了.x()和.y(),并且把它们猜对了,但是知道如何提取其他特性也很重要!在当前的形式中,它引发了:
AttributeError: 'TextItem' object has no attribute 'text'
如果选中source code,您会看到TextItem有一个QGraphicsTextItem来存储信息,因此如果要获取文本信息,应该使用该对象:
相关问题 更多 >
编程相关推荐