How to change the font-family?

78 views
Skip to first unread message

ip138

unread,
Feb 11, 2019, 10:24:50 AM2/11/19
to pyqtgraph
Hi,
I'm currently trying to change the font-family of pyqtgraph. I successfully changed font-size or font-color of the graphs, but how can I change the font-family?
Thank you for your help!

Patrick

unread,
Feb 18, 2019, 10:14:47 PM2/18/19
to pyqtgraph
Hi,

I don't know if this is the best way to do it, but something like this works for axis labels:

self.plot = self.addPlot()
self.plot.setLabels(left="Left axis")
font
= self.plot.getAxis("left").label.font()
font
.setFamily("Serif")
self.plot.getAxis("left").label.setFont(font)
self.plot.getAxis("left").setTickFont(font)

For other items, you may need to do something similar, but look at the code to see what the QtGui.QGraphicsTextItem is called. For example, for a TextItem (http://www.pyqtgraph.org/documentation/_modules/pyqtgraph/graphicsItems/TextItem.html#TextItem) you would use t.textItem.font() and t.textItem.setFont().

Patrick

ip138

unread,
Feb 19, 2019, 5:55:48 AM2/19/19
to pyqtgraph
Thank you!

That works perfect for everything, except for the title:

font = self.plots[key]["item"].titleLabel.font()
font.setFamily("Serif")
self.plots[key]["item"].setFont(font)

Is there anything I overlook?

Greetings,
Fabian

Patrick

unread,
Feb 19, 2019, 6:25:49 AM2/19/19
to pyqtgraph
Hi,

To modify my example from before, try something like:

self.plot = self.addPlot(title="Plot title")
font
= self.plot.titleLabel.item.font()
font
.setFamily("Serif")
p1
.titleLabel.item.setFont(font)

I think the issue is that the reference to titleLabel is actually a LabelItem object, so you then need to dig into it to get the reference to item, which is the QGraphicsTextItem object within.


Patrick

Reply all
Reply to author
Forward
0 new messages