QTextDocument: print underlined font
-
Hi, all!
I use QTextDocument printing. Code something like this:void MainWindow::on_btnPrint_clicked()
QPrinter printer(QPrinter::HighResolution); printer.setOutputFormat(QPrinter::NativeFormat); printer.setOrientation(QPrinter::Portrait); printer.setPageMargins(20, 10, 20, 10, QPrinter::Millimeter); QPrintPreviewDialog preview(&printer); connect(&preview, SIGNAL(paintRequested(QPrinter *)), SLOT(preview(QPrinter *))); preview.exec();
void MainWindow::preview(QPrinter *printer)
QPainter painter(printer); painter.setRenderHints(QPainter::TextAntialiasing); QString html = "<u>Underline string</u>"; QFont font; font.setFamily("Times New Roman"); font.setPointSize(20); painter.setFont(font); QTextDocument doc; doc.setDefaultFont(font); doc.documentLayout()->setPaintDevice(printer); doc.setPageSize(QSizeF(printer->pageRect().size())); doc.setHtml(html); doc.drawContents(&painter);
Printing underlined font in Linux and Windows get different. On Windows underscore line runs right under the letters.
screenshot
What could be wrong? How to achieve the display underscore line below on Windows?P.S. Forgive for my English.
-
Hi, all!
I use QTextDocument printing. Code something like this:void MainWindow::on_btnPrint_clicked()
QPrinter printer(QPrinter::HighResolution); printer.setOutputFormat(QPrinter::NativeFormat); printer.setOrientation(QPrinter::Portrait); printer.setPageMargins(20, 10, 20, 10, QPrinter::Millimeter); QPrintPreviewDialog preview(&printer); connect(&preview, SIGNAL(paintRequested(QPrinter *)), SLOT(preview(QPrinter *))); preview.exec();
void MainWindow::preview(QPrinter *printer)
QPainter painter(printer); painter.setRenderHints(QPainter::TextAntialiasing); QString html = "<u>Underline string</u>"; QFont font; font.setFamily("Times New Roman"); font.setPointSize(20); painter.setFont(font); QTextDocument doc; doc.setDefaultFont(font); doc.documentLayout()->setPaintDevice(printer); doc.setPageSize(QSizeF(printer->pageRect().size())); doc.setHtml(html); doc.drawContents(&painter);
Printing underlined font in Linux and Windows get different. On Windows underscore line runs right under the letters.
screenshot
What could be wrong? How to achieve the display underscore line below on Windows?P.S. Forgive for my English.
@Aleksey_A
I am as green to Qt as one can be, a newbie for sure.
But here goes: Maybe changing the QPrinter printer(QPrinter::HighResolution) to
QPrinter printer(QPrinter::ScreenResolution) would help.