Nominate our 2022 Qt Champions!

Qml and Thermal Printer

  • Hi,

    I've made a tiny utilitary to generate labels for my compagny.
    I used QML, because it's very easy to do this, rather than use a QPainter.
    I export the Item as a QImage using grabToImage and I print it.


    However, i've an issue.
    As all fonts are antialiased the printing is really ugly.
    I've tried to code a quick dirty way to resolve it using a font provider which set font.setStyleStrategy(QFont::NoAntialias) but it seems to have no effect.

    Is someone have a suggestion to make this program work as expected ?


  • Hi. I'd try setting renderType to Text.NativeRendering. (see: renderType : enumeration)

  • It seems to have no decent solution to avoid the antialiasing of the text.
    But you can watch this code:

    The best solution I founded is to modify the image pixel by pixel.
    I assume QImage has a transparent background.
    This code draw a pixel white or black based on its original alpha value.
    flipflop variable is a quint8 (0 to 255).

        QRgb *st = (QRgb *) img.bits();
        quint64 pixelCount = img.width() * img.height();
        for (quint64 p = 0; p < pixelCount; p++) {
            if (Q_LIKELY(qAlpha(st[p]) < flipflop_))
                st[p] = 0xffffffff;
                st[p] = 0xff000000;
        painter.drawImage( curPrinter_->paperRect(), img);

  • Banned

    This post is deleted!

Log in to reply