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:

Qt Code:
  1. #include <QtGui/QApplication>
  2. #include <QDialog>
  3. #include <QTextBrowser>
  4. #include <QDebug>
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8. QApplication a(argc, argv);
  9. QDialog dlg;
  10. QTextBrowser textBrowser(&dlg);
  11. textBrowser.setHtml("<h1 style=\"font-size:100pt;\">Test</h1>");
  12.  
  13. #if 1
  14. QString html = textBrowser.toHtml();
  15. qDebug() << html;
  16. textBrowser.setHtml(html);
  17. #endif
  18.  
  19. textBrowser.setGeometry(0, 0, 500, 500);
  20. dlg.setGeometry(0, 0, 500, 500);
  21. dlg.exec();
  22. return 0;
  23. }
To copy to clipboard, switch view to plain text mode 

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)