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. Linux + Qt + QLineEdit + TTF = Nightmare
QtWS25 Last Chance

Linux + Qt + QLineEdit + TTF = Nightmare

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 2 Posters 2.9k Views
  • 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.
  • Q Offline
    Q Offline
    QtAndLinux
    wrote on last edited by
    #1

    I am currently using Qt 4.8.6 on RHEL 7.1

    When I try and use my TFF font for my QLineEdit, my font is getting substituted with something default. On Windows everything works great, but on Linux...

    Any assistance would be GREATLY appreciated.

    THANKS!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mostefa
      wrote on last edited by
      #2

      Hi @QtAndLinux

      How are you using your font with QLineEdit?

      Is it with stylesheet?

      you can add your font like this, for me i prefer add things like this in main.cpp :

      QFontDatabase::addApplicationFont("path_to_your_font/your_font_name.ttf");
      

      After that with Qt stylesheet you can set font of your QLineEdit

      QLineEdit{
      ...
      font-family: your_font_name; // here add your font without .ttf
      ...
      }
      

      I tested this a lot of time with my Qt applicatiojn and it worked without without any problem

      Q 1 Reply Last reply
      0
      • M mostefa

        Hi @QtAndLinux

        How are you using your font with QLineEdit?

        Is it with stylesheet?

        you can add your font like this, for me i prefer add things like this in main.cpp :

        QFontDatabase::addApplicationFont("path_to_your_font/your_font_name.ttf");
        

        After that with Qt stylesheet you can set font of your QLineEdit

        QLineEdit{
        ...
        font-family: your_font_name; // here add your font without .ttf
        ...
        }
        

        I tested this a lot of time with my Qt applicatiojn and it worked without without any problem

        Q Offline
        Q Offline
        QtAndLinux
        wrote on last edited by QtAndLinux
        #3

        @mostefa said in Linux + Qt + QLineEdit + TTF = Nightmare:

        Hi @QtAndLinux

        How are you using your font with QLineEdit?

        Is it with stylesheet?

        you can add your font like this, for me i prefer add things like this in main.cpp :

        QFontDatabase::addApplicationFont("path_to_your_font/your_font_name.ttf");
        

        After that with Qt stylesheet you can set font of your QLineEdit

        QLineEdit{
        ...
        font-family: your_font_name; // here add your font without .ttf
        ...
        }
        

        I tested this a lot of time with my Qt applicatiojn and it worked without without any problem

        Currently I am not using stylesheets.

        To set the font I've tried:

        1. Select the QLineEdit in Qt Creator ( QWidget - font ) and select the font
        2. Add the font to the QFontDatabase and then use QLineEdit.setFont

        If I check the QFontDatase, my font is there and I can get the family, style and sizes...

        UPDATE
        Added a stylesheet:

        1. I can set the text color
        2. I can set the background color
        3. Still can't set the font
        M 1 Reply Last reply
        0
        • Q QtAndLinux

          @mostefa said in Linux + Qt + QLineEdit + TTF = Nightmare:

          Hi @QtAndLinux

          How are you using your font with QLineEdit?

          Is it with stylesheet?

          you can add your font like this, for me i prefer add things like this in main.cpp :

          QFontDatabase::addApplicationFont("path_to_your_font/your_font_name.ttf");
          

          After that with Qt stylesheet you can set font of your QLineEdit

          QLineEdit{
          ...
          font-family: your_font_name; // here add your font without .ttf
          ...
          }
          

          I tested this a lot of time with my Qt applicatiojn and it worked without without any problem

          Currently I am not using stylesheets.

          To set the font I've tried:

          1. Select the QLineEdit in Qt Creator ( QWidget - font ) and select the font
          2. Add the font to the QFontDatabase and then use QLineEdit.setFont

          If I check the QFontDatase, my font is there and I can get the family, style and sizes...

          UPDATE
          Added a stylesheet:

          1. I can set the text color
          2. I can set the background color
          3. Still can't set the font
          M Offline
          M Offline
          mostefa
          wrote on last edited by mostefa
          #4

          @QtAndLinux said in Linux + Qt + QLineEdit + TTF = Nightmare:

          @mostefa said in Linux + Qt + QLineEdit + TTF = Nightmare:

          Hi @QtAndLinux

          How are you using your font with QLineEdit?

          Is it with stylesheet?

          you can add your font like this, for me i prefer add things like this in main.cpp :

          QFontDatabase::addApplicationFont("path_to_your_font/your_font_name.ttf");
          

          After that with Qt stylesheet you can set font of your QLineEdit

          QLineEdit{
          ...
          font-family: your_font_name; // here add your font without .ttf
          ...
          }
          

          I tested this a lot of time with my Qt applicatiojn and it worked without without any problem

          Currently I am not using stylesheets.

          To set the font I've tried:

          1. Select the QLineEdit in Qt Creator ( QWidget - font ) and select the font
          2. Add the font to the QFontDatabase and then use QLineEdit.setFont

          If I check the QFontDatase, my font is there and I can get the family, style and sizes...

          UPDATE
          Added a stylesheet:

          1. I can set the text color
          2. I can set the background color
          3. Still can't set the font

          Hi again , after few search i think that is is what you need to do

          int id =QFontDatabase::addApplicationFont(":/path_to_your_font/your_font_family.ttf");
              QString customFontFamilyName = QFontDatabase::applicationFontFamilies(id).at(0);
          
              qDebug() << customFontFamilyName;// this will give the exact name of the font
          

          you can set font of qlineedit like this:

          QFont customFont;
              customFont.setFamily(customFontFamilyName);
               ui->lineEdit->setFont(customFont);
          

          or in stylesheet:

          QLineEdit 
          {
             font-family:  customFontFamilyName;
          }
          

          Try and keep me informed !

          Q 1 Reply Last reply
          0
          • M mostefa

            @QtAndLinux said in Linux + Qt + QLineEdit + TTF = Nightmare:

            @mostefa said in Linux + Qt + QLineEdit + TTF = Nightmare:

            Hi @QtAndLinux

            How are you using your font with QLineEdit?

            Is it with stylesheet?

            you can add your font like this, for me i prefer add things like this in main.cpp :

            QFontDatabase::addApplicationFont("path_to_your_font/your_font_name.ttf");
            

            After that with Qt stylesheet you can set font of your QLineEdit

            QLineEdit{
            ...
            font-family: your_font_name; // here add your font without .ttf
            ...
            }
            

            I tested this a lot of time with my Qt applicatiojn and it worked without without any problem

            Currently I am not using stylesheets.

            To set the font I've tried:

            1. Select the QLineEdit in Qt Creator ( QWidget - font ) and select the font
            2. Add the font to the QFontDatabase and then use QLineEdit.setFont

            If I check the QFontDatase, my font is there and I can get the family, style and sizes...

            UPDATE
            Added a stylesheet:

            1. I can set the text color
            2. I can set the background color
            3. Still can't set the font

            Hi again , after few search i think that is is what you need to do

            int id =QFontDatabase::addApplicationFont(":/path_to_your_font/your_font_family.ttf");
                QString customFontFamilyName = QFontDatabase::applicationFontFamilies(id).at(0);
            
                qDebug() << customFontFamilyName;// this will give the exact name of the font
            

            you can set font of qlineedit like this:

            QFont customFont;
                customFont.setFamily(customFontFamilyName);
                 ui->lineEdit->setFont(customFont);
            

            or in stylesheet:

            QLineEdit 
            {
               font-family:  customFontFamilyName;
            }
            

            Try and keep me informed !

            Q Offline
            Q Offline
            QtAndLinux
            wrote on last edited by
            #5

            @mostefa said in Linux + Qt + QLineEdit + TTF = Nightmare:

            Hi again , after few search i think that is is what you need to do

            int id =QFontDatabase::addApplicationFont(":/path_to_your_font/your_font_family.ttf");
                QString customFontFamilyName = QFontDatabase::applicationFontFamilies(id).at(0);
            
                qDebug() << customFontFamilyName;// this will give the exact name of the font
            

            you can set font of qlineedit like this:

            QFont customFont;
                customFont.setFamily(customFontFamilyName);
                 ui->lineEdit->setFont(customFont);
            

            or in stylesheet:

            QLineEdit 
            {
               font-family:  customFontFamilyName;
            }
            

            Try and keep me informed !

            First of all, thank you very much for the help!

            Tried adding the font to the QFontDatabase:

            1. The font gets added to the QFontDatabase
            2. The exact name of the font is what I was using previously
            3. Used setFont to set the QLineEdit font, but it is still not showing my TTF
            4. If I ui->lineEdit->font() exactMatch() is true and family() is set to customFontFamilyName

            Tried using the stylesheet:

            1. QLineEdit font is still not showing my TTF but text and background color are both set
            1 Reply Last reply
            0
            • M Offline
              M Offline
              mostefa
              wrote on last edited by
              #6

              @QtAndLinux

              This is really strange, except changing font are doing something else on your parent Widget?

              Is there any sample code that you could share with us?

              Q 1 Reply Last reply
              0
              • M mostefa

                @QtAndLinux

                This is really strange, except changing font are doing something else on your parent Widget?

                Is there any sample code that you could share with us?

                Q Offline
                Q Offline
                QtAndLinux
                wrote on last edited by
                #7

                @mostefa said in Linux + Qt + QLineEdit + TTF = Nightmare:

                @QtAndLinux

                This is really strange, except changing font are doing something else on your parent Widget?

                Is there any sample code that you could share with us?

                This is VERY strange. All of this works fine in Windows, but in Linux the QlineEdit just won't show the TTF.

                Here is my code without stylesheet:

                        int retCode = QFontDatabase::addApplicationFont(":/fonts/resources/pleasework.ttf");
                        QString customFontFamilyName = QFontDatabase::applicationFontFamilies(retCode).at(0);
                        qDebug() << customFontFamilyName;// this will give the exact name of the font
                
                        QFont customFont;
                        customFont.setFamily(customFontFamilyName);
                        ui.Input->setFont(customFont);
                

                Here is my code with a stylesheet:

                        int retCode = QFontDatabase::addApplicationFont(":/fonts/resources/pleasework.ttf");
                        app.setStyleSheet("QLineEdit { background: yellow; font-family: pleasework; }");
                
                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mostefa
                  wrote on last edited by mostefa
                  #8

                  Your code seems good,

                  I am out of idea , did you try with another font.ttf ?

                  Maybe the problem is due to this font on linux, could you test with another font?

                  Q 1 Reply Last reply
                  0
                  • M mostefa

                    Your code seems good,

                    I am out of idea , did you try with another font.ttf ?

                    Maybe the problem is due to this font on linux, could you test with another font?

                    Q Offline
                    Q Offline
                    QtAndLinux
                    wrote on last edited by
                    #9

                    @mostefa said in Linux + Qt + QLineEdit + TTF = Nightmare:

                    Your code seems good,

                    I am out of idea , did you try with another font.ttf ?

                    Maybe the problem is due to this font on linux, could you test with another font?

                    "FontAwesome" and "LKLUG" have the same problem:

                    1. Font Viewer shows the font without any problems
                    2. When I try use the font with a QLineEdit it gets replaced

                    Do "FontAwesome" and "LKLUG" work for your QLineEdit?

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mostefa
                      wrote on last edited by
                      #10

                      @QtAndLinux

                      I am not having these fonts on my UBUNTU,

                      What about other fonts(except "FontAwesome" and "LKLUG") , they work without any problem?

                      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