Pasting emoji in QT QTextEdit

早过忘川 提交于 2019-12-03 08:08:39
mhcuervo

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.

The Qt documentation of QTextEdit::paste() says: To change the behavior of this function, i.e. to modify what QTextEdit can paste and how it is being pasted, reimplement the virtual canInsertFromMimeData() and insertFromMimeData() functions.

There you should be able to convert the pasted data e.g. to an HTML img element pointing to a file that is embedded into the application by ressource compiler (or to image file on disk).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!