WordWrap word boundary, non-breaking <nobr>, special character slash "/", wrap/split issue.
-
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.1Window {
id: idRootwidth: 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! -
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 :( -
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 -
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))