PDA

View Full Version : QTextBrowser font-size stylesheet doesn't work all the time



frankbuss
12th August 2010, 17:05
I'm trying to display this HTML with a QTextBrowser:


<h1 style="font-size:100pt;">Test</h1>

The strange thing is that it doesn't work with setHtml, but looks like the stylesheet is parsed, because when I use toHtml (which wraps it in a span-element), and set it again with setHtml, it works.

Example code:



#include <QtGui/QApplication>
#include <QDialog>
#include <QTextBrowser>
#include <QDebug>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QDialog dlg;
QTextBrowser textBrowser(&dlg);
textBrowser.setHtml("<h1 style=\"font-size:100pt;\">Test</h1>");

#if 1
QString html = textBrowser.toHtml();
qDebug() << html;
textBrowser.setHtml(html);
#endif

textBrowser.setGeometry(0, 0, 500, 500);
dlg.setGeometry(0, 0, 500, 500);
dlg.exec();
return 0;
}


Change "#if 1" to "#if 0" and it doesn't work. But the toHtml and setHtml workaround has other problems. Maybe I'm doing something wrong? Or is this a bug? (I've tried it with Qt 4.6.2)