drawText cannot draw latin word correctly
-
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 qDebugthe 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 -
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 qDebugthe 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@yifong Could be the font. You could try another font using http://doc.qt.io/archives/qt-4.8/qpainter.html#setFont
-
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 qDebugthe 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@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")
-
@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")
@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. :)