I'm attempting to generate a PDF file from `QTextDocument`, which is working just fine. The issue comes when I want to use a custom font for just a specific `<p></p>` object. I tried using the standard means of `QFontDatabase::addApplicationFont()` which successfully gets the font loaded into the application, but for some reason it writes all of the `QString` based variables that are added to `messageBody` in this font instead of that specified by `QTextFocument.setDefaultFont()`, or even a manually via `style={font-family:}`.

Am I doing this wrong, or overlooking something here, or is this some kind of bug?

Qt Code:
  1. int main(int argc, char *argv[])
  2. {
  3. QApplication a(argc,argv);
  5. // With this added, all hell breaks loose
  6. QFontDatabase::addApplicationFont(":/Barcode.ttf");
  8. QString messageBody;
  9. QString serialNumber = "ABC123";
  10. messageBody += "<p style='font-size: large;'><b>Serial Number:</b> " + serialNumber + "</p>";
  11. messageBody += "<p style='font-size: large; font-family=\"Console\"'><b>Serial Number:</b> " + serialNumber + "</p>";
  14. QTextDocument document;
  15. document.setHtml(messageBody);
  17. QFont myfont("Console", 8, QFont::Normal);
  18. document.setDefaultFont(myfont);
  20. QPrinter printer(QPrinter::PrinterResolution);
  21. printer.setOutputFormat(QPrinter::PdfFormat);
  22. printer.setOutputFileName("test.pdf");
  24. document.print(&printer);
  26. return 0;
  27. }
To copy to clipboard, switch view to plain text mode 

In either case I would get the output PDF like so:

I can't wrap my head around why/how it would differentiate the base QString (messageBody) from those that are concatenated into it (serialNumber)?