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. WordWrap word boundary, non-breaking <nobr>, special character slash "/", wrap/split issue.
Forum Updated to NodeBB v4.3 + New Features

WordWrap word boundary, non-breaking <nobr>, special character slash "/", wrap/split issue.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
wrapmodewordwrapword boundaryspecial charactseparator
5 Posts 3 Posters 3.0k Views 2 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.
  • B Offline
    B Offline
    billouparis
    wrote on last edited by A Former User
    #1

    Hello, I would like to display a text composed of several words with wrapMode set to Text.WordWrap enumeration value.
    This text contains what I consider being a word which contains a special character (a slash character) in the middle of the word itself. "90km/h"
    Sadly Qt is not considering this as a single word, and is splitting the word before the "h".

    Code example:
    import QtQuick 2.2
    import QtQuick.Window 2.1

    Window {
    id: idRoot

    width: 800
    height: 480
    visible: true
    
    Rectangle {
        id: pipoRect
        width : childrenRect.width
        height: width
        color:"blue"
        Text {
            wrapMode : Text.WordWrap
            id: pipoText
            width : 530
            height :200
            color: "yellow"
    
            font.pixelSize: 24
            text: "Défaut suspension: Limitez votre vitesse à 90km/h"
    
        }
    }
    

    }

    The "word" 90km/h is split on two lines, first line shows "90km/" and second line shows "h".
    What would be the best solution to get "90km/h" not split, and displayed in this case on the second line?

    Of course this text is just one example, the text can be random, and I need a generic solution to prevent Qt to consider / as a word boundary.
    Thank you for any hint!

    1 Reply Last reply
    1
    • B Offline
      B Offline
      billouparis
      wrote on last edited by
      #2

      Well I thought I found a kind of solution by using this line:

      text: "Défaut suspension: Limitez votre vitesse à <nobr>90km/h</nobr>"
      But this just does not work and still provide the same result, with the "90km/" on the first line and the "h" on the second line.
      And I'm expecting "90km/h" on the second line instead :(

      1 Reply Last reply
      1
      • B Offline
        B Offline
        billouparis
        wrote on last edited by
        #3

        It seems ok with this!
        text: "Défaut suspension: Limitez votre vitesse à 90km\u2060/\u2060h"

        This is the unicode character for word joiner!
        Good night!
        Bill

        1 Reply Last reply
        1
        • A Offline
          A Offline
          Andriy
          wrote on last edited by
          #4

          This works for me as well. I have the same issue, but in QTextBlock, when text symbols immediately break after slash('/') symbol. Thanks alot for your research.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            Donald Duck
            wrote on last edited by Donald Duck
            #5

            Normal C strings don't support unicode, so doing QString("\u2060") will give a compiler warning saying "C4566: character represented by universal-character-name '\u2060' cannot be represented in the current code page (1252)", and will replace the \u2060 characters with question marks.

            Instead, it works to do:

            QString("Défaut suspension: Limitez votre vitesse à 90km") + QChar(0x2060) + "/" + QChar(0x2060) + "h"
            

            Or, if that's too difficult to read, this also works:

            QString("Défaut suspension: Limitez votre vitesse à 90km\1/\1h").replace('\1', QChar(0x2060))
            
            1 Reply Last reply
            2

            • Login

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