Results 1 to 6 of 6

Thread: How to paint unicode surrogate pairs using QPainter?

  1. #1
    Join Date
    Dec 2012
    Posts
    4

    Default How to paint unicode surrogate pairs using QPainter?

    If a unicode character with code values above 65535, it will be stored using surrogate pairs, I store it in an QString object, and draw it with QPainter, but nothing will appear, is this a bug? or QPainter’s drawText just doesn’t support characters above 65535?
    I have set a correct font, the same font in other text editors / word processers can display this character.
    Here is a unicode character for test: http://www.unicode.org/cgi-bin/GetUn...odepoint=22489

    QChar data[2]={0xd849,0xdc89};
    QString str(data, 2);

    QRect rect(0, 0, width(), height());
    m_backingStore->beginPaint(rect);

    QPaintDevice *device = m_backingStore->paintDevice();
    QPainter painter(device);

    QFont songTi(tr("simsun"), 12, 12);
    painter.setFont(songTi);

    painter.fillRect(0, 0, width(), height(), Qt::green);
    painter.drawText(QRectF(100, 100, width(), height()), str);

    m_backingStore->endPaint();
    m_backingStore->flush(rect);

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to paint unicode surrogate pairs using QPainter?

    How about:
    Qt Code:
    1. QString s(QChar(140425));
    2. painter.drawText(..., s);
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2012
    Posts
    4

    Default Re: How to paint unicode surrogate pairs using QPainter?

    Quote Originally Posted by wysota View Post
    How about:
    Qt Code:
    1. QString s(QChar(140425));
    2. painter.drawText(..., s);
    To copy to clipboard, switch view to plain text mode 
    Thanks, but it doesn't work, I tried.

    Documents for QChar:
    The QChar class provides a 16-bit Unicode character.
    In Qt, Unicode characters are 16-bit entities without any markup or structure. This class represents such an entity. It is lightweight, so it can be used everywhere. Most compilers treat it like a unsigned short.

    I have tried to input the same character in a QTextEdit widget, it can not display this character too.
    So, I think it's a bug, and I posted a bug report, but no one care about my bug report, maybe they are at holiday, or maybe there's too many other more important bugs to deal.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to paint unicode surrogate pairs using QPainter?

    Maybe you should first convert your character to UTF-16 and then read it with QChar?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Dec 2012
    Posts
    4

    Default Re: How to paint unicode surrogate pairs using QPainter?

    Yes, and I'm sure my str encoding is UTF-16.
    My bug report's status is [Open] now, I hope someone can confirm and fix it before the next release.

    And, by the way, do you have some experience in dealing with text input method? For example, using Qt's public API to make a text editor control that can accept input from an input method, and can control the input method window's position.
    I can get the input, but don't know how to control the input method window's position.
    Here is a video about how we use input method, you can see that the input method's compositing window is moving with the caret.

    Thanks, wysota.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to paint unicode surrogate pairs using QPainter?

    Quote Originally Posted by BobWu View Post
    Yes, and I'm sure my str encoding is UTF-16.
    Did you try this?

    Qt Code:
    1. QChar c(QChar::surrogateToUcs4(0xd849,0xdc89));
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QPainter immediate drawing outside paint event
    By sfcheng77 in forum Qt Programming
    Replies: 1
    Last Post: 23rd February 2011, 06:39
  2. Replies: 5
    Last Post: 15th February 2011, 01:35
  3. QPainter::begin: Cannot paint on a null pixmap
    By sabeesh in forum Qt Programming
    Replies: 5
    Last Post: 27th July 2010, 18:03
  4. How to paint (QPainter) on a label ?
    By d@nyal in forum Newbie
    Replies: 1
    Last Post: 29th May 2010, 18:39

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.