简体   繁体   中英

PyQt5, Qlabel text in multiple colors

how can i set multiple colors inside a Qlabel text? for example:

Qlabel.setText("Hello World!")

I want the "Hello" to be in blue, the "World" in red & the "?" in green is it possible?

I found that answer online for QT but this is not Python language:

ql->setText("<font color=\"blue\">Hello</font> <font color=\"red\">World</font><font color=\"green">!</font>");

It's easy, if you're familiar with HTML: Do something like this:

QLabel.setText('<font color="blue">Hello</font><font color="red"> World</font><font color="green">!</font>')

Hope this helps:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM