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.

    0_1501263303311_p.png

    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 ?

    Thanks.


  • Moderators

    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:
    https://github.com/danieloneill/ComponentPrinter

    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;
            else
                st[p] = 0xff000000;
        }
    
        painter.drawImage( curPrinter_->paperRect(), img);

Log in to reply
 

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