Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. drawText cannot draw latin word correctly

drawText cannot draw latin word correctly

Scheduled Pinned Locked Moved Solved Mobile and Embedded
5 Posts 3 Posters 1.1k Views
  • 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.
  • Y Offline
    Y Offline
    yifong
    wrote on last edited by
    #1

    Hi All:
    I am using QT 4.7.3 under embedded linux platform.
    I got a problem.

    I use command (mount -o iocharset=iso8859-1,utf8) to mount usb disk.
    and get the file name list in QT application.
    And there is a file that name is FüllungRaupeStep
    The file name could be show correctly in linux console.
    But , it shows FüllungRaupeStep in my GUI when I invoke QPainter.drawText to show it.
    I tried to show it by qDebug

    the result as following.

    QString text = tr("FüllungRaupeStep");
    qDebug() << text; //output is FüllungRaupeStep (O)
    qDebug() << text.toUtf8(); //output is FüllungRaupeStep(X)
    qDebug() << text.toLatin1(); //output is FüllungRaupeStep(O)

    painter.drawText(rect, align_flag, text.toLatin1()); //output is FüllungRaupeStep(X)
    painter.drawText(rect, align_flag, text.); //output is FüllungRaupeStep(X)
    painter.drawText(rect, align_flag, text.toUtf8()); //output is FüllungRaupeStep(X)

    Does any one have idea?
    Thanks

    jsulmJ raven-worxR 2 Replies Last reply
    0
    • Y yifong

      Hi All:
      I am using QT 4.7.3 under embedded linux platform.
      I got a problem.

      I use command (mount -o iocharset=iso8859-1,utf8) to mount usb disk.
      and get the file name list in QT application.
      And there is a file that name is FüllungRaupeStep
      The file name could be show correctly in linux console.
      But , it shows FüllungRaupeStep in my GUI when I invoke QPainter.drawText to show it.
      I tried to show it by qDebug

      the result as following.

      QString text = tr("FüllungRaupeStep");
      qDebug() << text; //output is FüllungRaupeStep (O)
      qDebug() << text.toUtf8(); //output is FüllungRaupeStep(X)
      qDebug() << text.toLatin1(); //output is FüllungRaupeStep(O)

      painter.drawText(rect, align_flag, text.toLatin1()); //output is FüllungRaupeStep(X)
      painter.drawText(rect, align_flag, text.); //output is FüllungRaupeStep(X)
      painter.drawText(rect, align_flag, text.toUtf8()); //output is FüllungRaupeStep(X)

      Does any one have idea?
      Thanks

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @yifong Could be the font. You could try another font using http://doc.qt.io/archives/qt-4.8/qpainter.html#setFont

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • Y Offline
        Y Offline
        yifong
        wrote on last edited by yifong
        #3

        Hi:
        Thanks for reply.

        I think it is not font problem , because ü could be show if I use following method.
        painter.drawText(rect, align_flag, QString(QChar(0x00FC)); // ü is showed correctly.
        So, the applied font is support to show ü. :)

        1 Reply Last reply
        0
        • Y yifong

          Hi All:
          I am using QT 4.7.3 under embedded linux platform.
          I got a problem.

          I use command (mount -o iocharset=iso8859-1,utf8) to mount usb disk.
          and get the file name list in QT application.
          And there is a file that name is FüllungRaupeStep
          The file name could be show correctly in linux console.
          But , it shows FüllungRaupeStep in my GUI when I invoke QPainter.drawText to show it.
          I tried to show it by qDebug

          the result as following.

          QString text = tr("FüllungRaupeStep");
          qDebug() << text; //output is FüllungRaupeStep (O)
          qDebug() << text.toUtf8(); //output is FüllungRaupeStep(X)
          qDebug() << text.toLatin1(); //output is FüllungRaupeStep(O)

          painter.drawText(rect, align_flag, text.toLatin1()); //output is FüllungRaupeStep(X)
          painter.drawText(rect, align_flag, text.); //output is FüllungRaupeStep(X)
          painter.drawText(rect, align_flag, text.toUtf8()); //output is FüllungRaupeStep(X)

          Does any one have idea?
          Thanks

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @yifong
          the tr() methods expects the string to be latin-1 encoded. By passing "ü" the latin-1 representation is "ü" (of "ü" from UTF-8)
          So you are advised to pass only ASCII characters to tr() and translate them later (what i assume is your intention in the first place since you use tr()).

          If you don't want the string be translated simply use QString::fromUtf8("FüllungRaupeStep")

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          Y 1 Reply Last reply
          5
          • raven-worxR raven-worx

            @yifong
            the tr() methods expects the string to be latin-1 encoded. By passing "ü" the latin-1 representation is "ü" (of "ü" from UTF-8)
            So you are advised to pass only ASCII characters to tr() and translate them later (what i assume is your intention in the first place since you use tr()).

            If you don't want the string be translated simply use QString::fromUtf8("FüllungRaupeStep")

            Y Offline
            Y Offline
            yifong
            wrote on last edited by
            #5

            @raven-worx
            Thanks for your answer
            You are right .
            Finally I solve this problem by following method.

            painter.drawText(rect, align_flag, QString::fromUtf8(qPrintable(text)));
            "ü" could be show correctly. :)

            1 Reply Last reply
            1

            • Login

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