View Full Version : QPainter drawText with different language
Hello,
How can I use QPainter to draw string that is not English origin?
I have a QLineEdit that accept external input from user, and then draw it using QPainter:
QPainter->drawText( QPoint( 0, 0 ), QLineEdit->text() );
If user inputs English, Spanish, German, etc, the draw is fine.
However, when user type Chinese, Japanese, or Korean that are not English origin, the QPainter doesn't draw anything...
How can I fix the problem?
Thank you for help.
Lykurg
11th June 2009, 19:38
Does the used font for your painter support the Chinese/etc. fonts?
(And is the given point not the bottom left of the base line of the characters? maybe the text is drawn outside your display area.)
Does the used font for your painter support the Chinese/etc. fonts?
(And is the given point not the bottom left of the base line of the characters? maybe the text is drawn outside your display area.)
The QPainter draws correctly if I do QPainter->drawText( QPointF, QObject::tr( "text" ) ), where text translation can be found in the *.qm file
However, it doesn't draw with QPainter->drawText( QPointF, text ), where text is already a string of Chinese character. My Linux system has the used font installed....
It becomes interesting.
I did QObject::tr( text ), and if text is already a Chinese character, it didn't work. I remove QObject::tr and it works.
The problem is if the text is an English string and I want to translate to Chinese, it will not do the translation because QObject::tr is removed...
How can I take care bother cases?
Thanks
Lykurg
11th June 2009, 20:54
I did QObject::tr( text ), and if text is already a Chinese character, it didn't work. I remove QObject::tr and it works.
But that means that something with your translation file is not correct, because tr() returns the same string if no translation is found. What does a qWarning() << QObject::tr( text );? If it displays "" then your problem is in that (=translation file/system) not in the painter.
How can I take care bother cases?
Before that, better investigate some time in the tr() misbehavior of yours.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.