Reputation: 1115
When creating a TextItem to be added to a plotItem in PyQtGraph, I know it is possible to format the text using html code, however I was wondering how to format the text (i.e. change font size) when updating the text through TextItem.setText()? or do I need to destroy/re-create a TextItem?
Upvotes: 1
Views: 3469
Reputation: 41
I use TextItem.setFont()
to change the font size:
from PySide2.QtGui import QFont
font = QFont()
font.setPixelSize(9)
textDie = TextItem('Your string', anchor=(0.5, 0.5))
ui.outPlot.addItem(textDie) # ui.outPlot is the pyqtgraph object in my GUI.
textDie.setPos(x,y)
textDie.setFont(font)
Upvotes: 1
Reputation: 11644
It is not documented, but the method you want is TextItem.setHtml()
.
Upvotes: 5