HTML fails in 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!开发者_如何学Go
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.
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
.
I just tried this code and it's working.
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("<strong>Hello</strong> "
"<font color=red>Wanderson !");
label->show();
return app.exec();
}
精彩评论