Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to display emoji with next to normal text



  • 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



  • My bad
    I had set 077 umask (cause I'm paranoid) and had no read permission set on /etc/fonts/local.conf which had fallback configuration.
    I gave read permission to all and reran fc-cache and now everything is working fine.


  • Lifetime Qt Champion

    @noone

    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.
    alt text

    (just pasted from forum)



  • My bad
    I had set 077 umask (cause I'm paranoid) and had no read permission set on /etc/fonts/local.conf which had fallback configuration.
    I gave read permission to all and reran fc-cache and now everything is working fine.


Log in to reply