Results 1 to 5 of 5

Thread: QPainter drawText with different language

  1. #1
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QPainter drawText with different language

    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.)

  3. #3
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPainter drawText with different language

    Quote Originally Posted by Lykurg View Post
    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....

  4. #4
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QPainter drawText with different language

    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

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QPainter drawText with different language

    Quote Originally Posted by lni View Post
    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.

Similar Threads

  1. Replies: 4
    Last Post: 6th February 2009, 11:21
  2. QPainter - Retrieve drawText size
    By Raccoon29 in forum Qt Programming
    Replies: 2
    Last Post: 2nd May 2008, 09:22
  3. Qt drawText QPainter
    By bunjee in forum Qt Programming
    Replies: 1
    Last Post: 7th April 2008, 19:00
  4. QPainter update()
    By csvivek in forum Qt Programming
    Replies: 5
    Last Post: 24th March 2008, 09:42
  5. Replies: 7
    Last Post: 20th March 2006, 20:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.