Print text without "QTextDocument"

  • I try to print labels on a Zebra from Qt
    I use ZPL code to send directly to a printer "Generic / Text Only".

    For information, I noticed that:
    . When I print from Notepad (Windows): Printing is good
    . When I print from WordPad (Windows): Printing is the same as with Qt (add spaces)

    I think there must be something wrong with the layout engine (wordwrap? Text "formatted")

    So when I use this way QTextDocument

    @ QTextDocument doc ("ZPL Command");
    Doc.print (& printer);@

    Spaces are added in all text labels
    Will it have a way to print "as notepad"?

    NB: Same problem as:

  • Lifetime Qt Champion


    You could try with QPainter directly. Have a look at the "Printing with Qt" chapter of Qt's documentation.

    Hope it helps

  • Hi,

    Thanks for the reply, I found the time to test with QPainter, but nothing print. Is there an error in this code?

    @QWebElement e = frame->findFirstElement("...");
    // ....
    QPainter painter;
    painter.drawText(QPoint(50, 50), e.toPlainText());

    Otherwise, I partially solved the problem by setting the font
    With default font, many spaces are added. When I set it to "Courier" 7pt, and with CR before each text, most problems are solved:

    @QWebElement e = frame->findFirstElement("...");
    // ....
    QTextDocument doc;
    QFont newFont(doc.defaultFont());
    newFont.setFamily("Courier New");

    But it would certainly be better with QPainter

  • Lifetime Qt Champion

    Are you sure you have a valid printer ?

  • Yes, it's the same for QPainter & QTextDocument

  • Lifetime Qt Champion

    How do you create the printer ?

  • @QPrinter printer(QPrinter::HighResolution);

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.