Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qml and Thermal Printer
Forum Updated to NodeBB v4.3 + New Features

Qml and Thermal Printer

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 3 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fero
    wrote on last edited by Fero
    #1

    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.

    ? 1 Reply Last reply
    0
    • F Fero

      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.

      ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

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

      1 Reply Last reply
      1
      • F Offline
        F Offline
        Fero
        wrote on last edited by Fero
        #3

        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);
        
        1 Reply Last reply
        0
        • F Offline
          F Offline
          Ferwas Jonzai
          Banned
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved