Pasting emoji in QT QTextEdit

前端 未结 2 1489
终归单人心
终归单人心 2021-02-09 23:31

I\'m trying to paste emoji\'s in the QT QTextEdit box but it\'s not getting recognized and it\'s showing as ??? or [][]

I\'m not talking about smiley, I\'m talking about

2条回答
  •  花落未央
    2021-02-10 00:05

    A considerable number of emoji characters are in the Unicode Standard. If you're, for example, developing with Qt 5.3 in Mac OS X 10.9, pasting emoji characters in text edits should work as it does when pasting any other character.

    The reason why your application is showing ?'s and/or []'s is because the current font (perhaps the default system font) doesn't provide representations for emoji "characters". You can find a proper font out there in the web. Check this for reference.

    Then you can add the font to your Qt application

    QFontDatabase fontDB;
    fontDB.addApplicationFont(":/A Font Supporting Emoji.ttf");
    

    and set it as the font for your application or only your QTextEdit if you prefer

    setFont(QFont(QStringLiteral("A Font Supporting Emoji")));
    

    With this your app should be able to display emoji.

提交回复
热议问题