Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] How to apply a font family as default through a Qt Quick app

[SOLVED] How to apply a font family as default through a Qt Quick app

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 4 Posters 15.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
    qgil
    wrote on last edited by
    #1

    Real use case: Nokia is encouraging developers to use Nokia Pure in apps targeting Nokia devices. Makes sense and the font looks nice. Now, how is the best way to implement this in a Qt Quick project? I could not find any hints in the QML docs and I have no idea about Qt/C++.

    I want to have Nokia Pure Text as default for all text strings. If a specific item requires a different font.family (e.g. Nokia Pure Header) then I would just need to add the parameter to the item itself.

    fwiw my first little Qt Quick pet project can be found at https://gitorious.org/testdef/testdef/trees/master/testdef

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      ZapB
      wrote on last edited by
      #2

      In the main() function add a call to "QApplication::setFont()":http://doc.qt.nokia.com/latest/qapplication.html#setFont. Your QML elements should then use the specified font as default.

      Nokia Certified Qt Specialist
      Interested in hearing about Qt related work

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qgil
        wrote on last edited by
        #3

        Thanks but the builder complains. Maybe I'm still doing something wrong?

        @#include <QtGui/QApplication>
        #include <QtDeclarative>

        int main(int argc, char *argv[])
        {
        QApplication app(argc, argv);
        QApplication::setFont("Nokia Pure Text");
        QDeclarativeView view;
        view.setSource(QUrl("qrc:/qml/main.qml"));
        view.showFullScreen();
        return app.exec();
        }
        @

        ...main.cpp:-1: In function 'int main(int, char**)':

        ...main.cpp:8: error: no matching function for call to 'QApplication::setFont(const char [16])'

        ...QtSDK/Madde/sysroots/harmattan-nokia-meego-arm-sysroot-1122-slim/usr/include/qt4/QtGui/qapplication.h:162: candidates are: static void QApplication::setFont(const QFont&, const char*)

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #4

          Try this :

          @QFont nokiaFont;
          nokiaFont.setFamily("Nokia Pure Text");
          QApplication::setFont(nokiaFont);
          @

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • Q Offline
            Q Offline
            qgil
            wrote on last edited by
            #5

            Thanks Eddy, the builder liked your code and digested it.

            1 Reply Last reply
            0
            • EddyE Offline
              EddyE Offline
              Eddy
              wrote on last edited by
              #6

              Lol
              And now you're going for the dessert!?

              I'm glad I could help!

              Qt Certified Specialist
              www.edalsolutions.be

              1 Reply Last reply
              0
              • N Offline
                N Offline
                NielsMayer
                wrote on last edited by
                #7

                What is the advantage of using the form Eddy posted and something like this:

                @int main(int argc, char *argv[])
                {
                QApplication app(argc, argv);
                #if defined(MEEGO_EDITION_HARMATTAN)
                app.setFont(QFont("Nokia Pure Text"));
                #endif
                ...
                @

                1 Reply Last reply
                0
                • Z Offline
                  Z Offline
                  ZapB
                  wrote on last edited by
                  #8

                  Eddy's code is more explicit and allows you to set additional properties on the QFont object before setting it as the application font.

                  The #if defined part means that it is only compiled in if you are targeting MeeGo.

                  Nokia Certified Qt Specialist
                  Interested in hearing about Qt related work

                  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