Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Text on QLabel with initalic will be changed to be oblong after addApplicationFont
Forum Updated to NodeBB v4.3 + New Features

Text on QLabel with initalic will be changed to be oblong after addApplicationFont

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 2 Posters 625 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MihanM Offline
    MihanM Offline
    Mihan
    wrote on last edited by
    #1

    Hi all

    I found my italic text made in ui file will be changed to oblong if using QFontDatabase::addApplicationFont().

    How should I modify it.

    Best regards
    Mihan

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      @Mihan Do you mean the "italic" text becomes "upright" or all the characters become a box-like glyph (e.g. "▯") on-screen?

      MihanM 2 Replies Last reply
      0
      • C ChrisW67

        @Mihan Do you mean the "italic" text becomes "upright" or all the characters become a box-like glyph (e.g. "▯") on-screen?

        MihanM Offline
        MihanM Offline
        Mihan
        wrote on last edited by
        #3

        @ChrisW67 "italic" will become "▯▯▯▯" on screen;

        C 1 Reply Last reply
        0
        • C ChrisW67

          @Mihan Do you mean the "italic" text becomes "upright" or all the characters become a box-like glyph (e.g. "▯") on-screen?

          MihanM Offline
          MihanM Offline
          Mihan
          wrote on last edited by
          #4

          @ChrisW67 Now I'm checking the italic() of the font I added.

          1 Reply Last reply
          0
          • MihanM Mihan

            @ChrisW67 "italic" will become "▯▯▯▯" on screen;

            C Offline
            C Offline
            ChrisW67
            wrote on last edited by
            #5

            @Mihan said in Text on QLabel with initalic will be changed to be oblong after addApplicationFont:

            @ChrisW67 "italic" will become "▯▯▯▯" on screen;

            Then it is likely that the font you have added to the database is a better match for the font family that the label is using, and the characters you are using in the label are not present in the new font.

            What is the font family that the label is using, the characters in the string, and the new font you add?

            MihanM 1 Reply Last reply
            0
            • C ChrisW67

              @Mihan said in Text on QLabel with initalic will be changed to be oblong after addApplicationFont:

              @ChrisW67 "italic" will become "▯▯▯▯" on screen;

              Then it is likely that the font you have added to the database is a better match for the font family that the label is using, and the characters you are using in the label are not present in the new font.

              What is the font family that the label is using, the characters in the string, and the new font you add?

              MihanM Offline
              MihanM Offline
              Mihan
              wrote on last edited by
              #6

              @ChrisW67 I checked the font family the label using, it's ""Sans Serif", this may be the default font family Qt using, Because I can not find it in the database.

              Also, I add "FontAwesome" into the database.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                ChrisW67
                wrote on last edited by ChrisW67
                #7

                So you are saying that this fails:

                #include <QApplication>
                #include <QLabel>
                #include <QFontDatabase>
                #include <QDebug>
                
                
                int main(int argc, char *argv[])
                {
                    QApplication a(argc, argv);
                    // Use you own path to the font here
                    QFontDatabase::addApplicationFont("/usr/share/fonts-font-awesome/fonts/FontAwesome.otf");
                
                    QFont font("Sans Serif");
                    font.setItalic(true);
                    QLabel label("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod\n"
                                 "tempor incididunt ut labore et dolore magna aliqua. ");
                    label.setFont(font);
                    label.show();
                
                    return a.exec();
                }
                
                MihanM 1 Reply Last reply
                0
                • C ChrisW67

                  So you are saying that this fails:

                  #include <QApplication>
                  #include <QLabel>
                  #include <QFontDatabase>
                  #include <QDebug>
                  
                  
                  int main(int argc, char *argv[])
                  {
                      QApplication a(argc, argv);
                      // Use you own path to the font here
                      QFontDatabase::addApplicationFont("/usr/share/fonts-font-awesome/fonts/FontAwesome.otf");
                  
                      QFont font("Sans Serif");
                      font.setItalic(true);
                      QLabel label("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod\n"
                                   "tempor incididunt ut labore et dolore magna aliqua. ");
                      label.setFont(font);
                      label.show();
                  
                      return a.exec();
                  }
                  
                  MihanM Offline
                  MihanM Offline
                  Mihan
                  wrote on last edited by
                  #8

                  @ChrisW67

                  Not really

                  the font will be set in ui file but it doesn't seem to really set the font name:

                  //ui_CQuickProbe.h
                  void setupUi(QDialog *CQuickProbe)
                  {
                      label = new QLabel(CQuickProbe);
                      label->setObjectName(QStringLiteral("label"));
                      QFont font;                                                 // HERE
                      font.setPointSize(13);
                      font.setItalic(true);
                      label->setFont(font);
                      label->setTextFormat(Qt::PlainText);
                  }
                  

                  the font in ui designer:
                  font_set_in_ui.png
                  but it will be set to "Sans Serif" after this dialog shown ( I get the font().family()).

                  BTW, The project is compiled for embeded linux.

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    ChrisW67
                    wrote on last edited by
                    #9

                    Yes, but does my example work for you or not?

                    MihanM 1 Reply Last reply
                    0
                    • C ChrisW67

                      Yes, but does my example work for you or not?

                      MihanM Offline
                      MihanM Offline
                      Mihan
                      wrote on last edited by
                      #10

                      @ChrisW67 Hi sorry for late
                      No, it doesn't work for me.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved