How to display emoji with next to normal text
Solved
General and Desktop
-
I want to display emojis with normal text which will be having its own separate font.
but if I set font to say 'source code pro' qt displays emoji's as squares and if I set the font to 'emoji', emoji's work but then my other text losses its font.
#include <QApplication> #include <QLabel> #include <QFont> int main(int argc, char *argv[]) { QApplication a(argc, argv); QFont f; f.setFamily("source code pro"); QLabel l1; l1.setFont(f); l1.setText("thiss is gost 👻 haha"); //workaround // l1.setText("thiss is gost <span style='font-family:emoji'>👻</span> haha"); // l1.setTextFormat(Qt::TextFormat::RichText); l1.show(); return a.exec(); }
is their any way to set fallback font as 'emoji' so qt will display emoji instead of squares ?
the workaround I found is to use richtext feature of qt. but i don't want to use it cause I'll be getting input from user
-
Hi
Sadly plain text cannot contain multiple fonts
so without rich text is not possible.Also, QLabel doesn't have any fallback font system.
Maybe you could use a TextEdit instead. It also uses rich text internally but is happy to accept formatted text.
(just pasted from forum)