Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML fails in Qt QLabel

Tags:

c++

html

qt

qlabel

When using a QLabel element filled with some html text, I have a problem: it does not simply render the HTML, it inserts some space around the html text.

The following renders ok:

A simple text!

The following fails:

A <strong>HTML</strong> text!

Actually, Qt renders everything okay, but always I have html in my text, there are some space around my text, however, in my application, this space becomes a real problem. All CSS I've tried fails, maybe I just do not know the exactly way to style it.

like image 519
Wanderson Silva Avatar asked Jan 20 '26 19:01

Wanderson Silva


1 Answers

Are you setting the text using setText() function? If you pass a QString which contains rich text in setText() parameter, the rich text is supposed to be rendered. If not, you can try to set the QLabel's textFormat to Qt::RichText.

like image 84
Donotalo Avatar answered Jan 23 '26 08:01

Donotalo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!