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. Issue with using text wrap for international language
QtWS25 Last Chance

Issue with using text wrap for international language

Scheduled Pinned Locked Moved QML and Qt Quick
18 Posts 6 Posters 11.8k 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.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #9

    As a work-around, would it be acceptable to use rich text, and put the different words in <span> elements for the time being? That should force wrapping at the spaces.

    "해리 포터와 죽음의 성물-1부" would become
    @
    "<html><span>해리</span> <span>포터와</span> <span>죽음의</span> <span>성물-1부</span></html>"
    @

    For inserting this for single sentences (no line breaks), something like this might work:
    @
    #include <QStringBuilder>

    QString spanify(const QString& input)
    {
    QStringList elements = input.split(QRegExp("\s"));
    QString result = QLatin1String("<html>");
    foreach (const QString element, elements) {
    result = result % QLatin1String("<span>") % element % QLatin1String("</span> ");
    }
    result.chop(1); //remove the last space;
    result = result % QLatin1String("</html>");

    return result;
    

    }
    @

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tuanster
      wrote on last edited by
      #10

      Andre,

      I just tried your solution and it still doesn't work. I tried putting the "<html><span>해리</span> <span>포터와</span> <span>죽음의</span> <span>성물-1부</span></html>" as the text value and changing the text format to rich text, but it's still showing the same output as before. In other words, it doesn't force wrapping at the spaces.

      Do you have other ideas for a work-around?

      Thanks!

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #11

        [quote author="tuanster" date="1302192466"]Andre,

        I just tried your solution and it still doesn't work. I tried putting the "<html><span>해리</span> <span>포터와</span> <span>죽음의</span> <span>성물-1부</span></html>" as the text value and changing the text format to rich text, but it's still showing the same output as before. In other words, it doesn't force wrapping at the spaces.

        Do you have other ideas for a work-around?

        Thanks!

        [/quote]

        Sorry, I'm out of ideas. It seemed that that should work, but I guess I was wrong. Sorry to have led you down a blind alley.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #12

          Just a guess: try to replace

          @
          <span>xxx</span>
          // with
          <span style="white-space:nowrap">xxx</span>
          @

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tuanster
            wrote on last edited by
            #13

            Thanks for another suggestion.

            I just tried it with the "white-space: nowrap" but no luck. It still doesn't work. If I put other attribute like color inside the span tag, the text's color is changed. But the text is still being wrapped in the middle of a word.

            QML Text element has a mind of its own.

            Any other ideas?

            1 Reply Last reply
            0
            • L Offline
              L Offline
              loma27
              wrote on last edited by
              #14

              Hello,

              Please try this.

              I have used Webview. I have tried this and it seems to be working fine for me.
              If this is feasible(changing from Text to Webview) or affordable for your application. This may work for you.

              @import QtQuick 1.0
              import QtWebKit 1.0

              Rectangle {
              width: 360
              height: 360

              WebView{
                  html : "<div>해리 포터와 죽음의 성물부</div>"
              }
              

              }@

              1 Reply Last reply
              0
              • L Offline
                L Offline
                loma27
                wrote on last edited by
                #15

                sorry for wrong code. Please check updated.

                @WebView{
                html : "<div>해리 포터와 죽음의 성물부</div>"
                }
                }@

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  loma27
                  wrote on last edited by
                  #16

                  i have given style width 100px to div but its not coming in comments.

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    tuanster
                    wrote on last edited by
                    #17

                    Hi Ioma27,

                    Thanks for your recommendation. It turns out you also have to add the span tag for it to work.

                    A sample working code is this:

                    WebView {
                        html : "<div><span>해리</span> <span>포터와</span> <span>죽음의</span> <span>성물부</span></div>"
                        preferredWidth: 140
                        preferredHeight: 400
                    }
                    
                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      Minkyu Park
                      wrote on last edited by
                      #18

                      Seems there is a patch applied to 5.14
                      https://code.qt.io/cgit/qt/qtbase.git/commit/?id=d1bab5b1e3d28c0e2925ad3208cea785af755d54

                      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