Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

python - Changing PyQt Text Browser font

I have Python code that launches a GUI, the GUI displays text. I want to format the text i.e. Bold, Italic, change font etc.

call.TextBrowserName.append("Lyrics:" + lyrics)

Above is an example of how I'm adding text to the text browser (it's a lyric scraping program)

I've tried:

call.TextBrowserName.SetFont('Arial')
call.TextBrowserName.QFont(SetFont(Arial))

Any help?

question from:https://stackoverflow.com/questions/65847017/changing-pyqt-text-browser-font

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is how I change the font:

self.text = QTextEdit(self)
self.text.move(100,100)

font = QFont()
font.setFamily(u"Arial")
font.setBold(True)
font.setWeight(75)

self.text.setFont(font)

What this does is turn the text into Arial, and makes it bold. To make it italic, try this:

font = QFont()
font.setFamily(u"Arial")
font.setItalic(True)

And for underline, you can do:

font = QFont()
font.setFamily(u"Arial")
font.setUnderline(True)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...