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. Embed fonts[Solved]
QtWS25 Last Chance

Embed fonts[Solved]

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 20.2k 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.
  • G Offline
    G Offline
    gauravofindia
    wrote on last edited by
    #1

    Hi Guys,

    how can i embed fonts in qt from a folder as a resource?

    Gaurav

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

      Like this?
      FontLoader { id: localFont; source: "fonts/whatever.ttf" }

      It should be possible to add the font into a resource file and then reference it using the qrc://fonts/whatever.ttf syntax if that's what you're asking.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        linlin_0
        wrote on last edited by
        #3

        hi ,
        i'm Struggling over that, what's the Solution ?

        thanks.

        linlin

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

          Hi,

          FontLoader ia a QML feature.
          You can try int QFontDatabase::addApplicationFont ( const QString & fileName ), but I'm not sure, whether it can load from a resource.
          Otherwise you can load the resource by hand and call int QFontDatabase::addApplicationFontFromData ( const QByteArray & fontData ) [static].
          Here you can find mor information:

          http://doc.qt.nokia.com/4.7/qfontdatabase.html#addApplicationFont

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • P Offline
            P Offline
            patburke
            wrote on last edited by
            #5

            The fonts example demonstrates use:
            http://doc.trolltech.com/4.7/declarative-text-fonts-fonts-qml.html

            If you want to use fonts in a resource, they work identically to images and other things inside a Qt resource file. Just create a new qrc file in Qt Creator (or whatever), add the fonts, then reference it using the qrc:// syntax rather then a raw file:// path one. There's a little documentation on the use of qrc urls here: http://doc.trolltech.com/latest/qdeclarativenetwork.html but I don't recall any specific examples.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              gauravofindia
              wrote on last edited by
              #6

              Thanks guys for the reply.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                gauravofindia
                wrote on last edited by
                #7

                One more quick question is there any way i can include fonts in a folder and give the path in css?

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  giesbert
                  wrote on last edited by
                  #8

                  On Windows, a font always needs to be installed in the windows fonts dir, but you can go the same way as with resources (load it dynamically with QFontDatabase::addApplicationFont). But at the css, you can just set the font name.

                  Nokia Certified Qt Specialist.
                  Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                  1 Reply Last reply
                  0
                  • ? This user is from outside of this forum
                    ? This user is from outside of this forum
                    Guest
                    wrote on last edited by
                    #9

                    hi gaurav, always better to start a new question in a separate thread .. will be easier for everyone to search later :) so can you move this to a new thread

                    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