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. Stylesheet: linking custom fonts
Qt 6.11 is out! See what's new in the release blog

Stylesheet: linking custom fonts

Scheduled Pinned Locked Moved General and Desktop
6 Posts 5 Posters 11.5k 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.
  • G Offline
    G Offline
    goocreations
    wrote on last edited by
    #1

    Hi all

    I have a specific font stored in a file (ttf). Now I want to link this font to my QLabel's font. I've done the following:

    @label->setStyleSheet("font-family: url(C:/font.tff);");@

    But this doesn't seem to work. Does anyone know how to link an external font to your Qt application's style sheet?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Peppy
      wrote on last edited by
      #2

      label->setFont() ?

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Chuck Gao
        wrote on last edited by
        #3

        Try QFontDatabase from Qt C++ or FontLoader from QML :)

        Try:
        @int QFontDatabase::addApplicationFont ( const QString & fileName ) [static]
        QStringList QFontDatabase::applicationFontFamilies ( int id ) [static]@

        @import QtQuick 1.0

        Column {
        FontLoader { id: fixedFont; name: "Courier" }
        FontLoader { id: webFont; source: "http://www.mysite.com/myfont.ttf" }

         Text { text: "Fixed-size font"; font.family: fixedFont.name }
         Text { text: "Fancy font"; font.family: webFont.name }
        

        }@

        Chuck

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goocreations
          wrote on last edited by
          #4

          cool, thanks

          1 Reply Last reply
          0
          • H Offline
            H Offline
            Hassan Kassem
            wrote on last edited by
            #5

            @Chuck:I have tried these two methods and it doesn't work on symbian
            The first method always return -1
            I am using Qt 4.7.3

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kjaer
              wrote on last edited by
              #6

              Chuck, I think it's important to know whether QT C++ uses True Type Fonts already installed in the user's computer or if we can deploy our chosen TTF, to be used in a computer that doesn't have this TTF previously installed.

              It seems a stupid doubt, but QT docs aren't clear enough - specially for beginners, like me. I don't know if I can use a specially designed personal TTF in my software (it would make my life easier, by using only Text Classes) or if I have to use bitmap images to get the exact text design I want in all plataforms.

              As there are differences about TTF handling in Linux... and also because sometimes we need to use a special TTF in our programs, TTF deployment without the need to install a new font in the target computer would be a very useful feature to me.

              I don't want to use QML - I am too old to learn a new language. In my old times, C++ was tough enough to be learned and in the present, I confess that QT libraries are being almost too much to be explored by a STL-er. :)

              What can you and other experts say about?

              (Please, forgive my awful english. It is not my mother language)

              Valdemar Katayama Kjaer
              Brazil

              [quote author="Chuck Gao" date="1306668207"]Try QFontDatabase from Qt C++ or FontLoader from QML :)

              Try:
              @int QFontDatabase::addApplicationFont ( const QString & fileName ) [static]
              QStringList QFontDatabase::applicationFontFamilies ( int id ) [static]@

              @import QtQuick 1.0

              Column {
              FontLoader { id: fixedFont; name: "Courier" }
              FontLoader { id: webFont; source: "http://www.mysite.com/myfont.ttf" }

               Text { text: "Fixed-size font"; font.family: fixedFont.name }
               Text { text: "Fancy font"; font.family: webFont.name }
              

              }@[/quote]

              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