Issue with using text wrap for international language
-
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;
}
@ -
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 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.
-
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?
-
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.0Rectangle {
width: 360
height: 360WebView{ html : "<div>해리 포터와 죽음의 성물부</div>" }
}@
-
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 }
-
Seems there is a patch applied to 5.14
https://code.qt.io/cgit/qt/qtbase.git/commit/?id=d1bab5b1e3d28c0e2925ad3208cea785af755d54