How to display emoji with next to normal text

  c++, qfont, qlabel, qt

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();
}

screenshot

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

Source: Windows Questions C++

LEAVE A COMMENT