Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Set default font for qml controls
Qt 6.12 LTS is out! See what's new in the release blog

Set default font for qml controls

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 14.5k Views 3 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.
  • R Offline
    R Offline
    Rem-Kolomna
    wrote on last edited by
    #1

    I load my qml scene int QQuickWindow using this code:

    QQmlComponent *comp = new QQmlComponent(engine, 
      QUrl("qrc:/controllers/sample.qml"), contentItem());  
     QObject *obj = comp->create();
     QQmlProperty::write(obj, "parent", QVariant::fromValue<QObject*>(contentItem()));
    

    But font in labels and text fields is small. Is it possible to specify default font in qml?

    p3c0P 1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi!
      In main.cpp:

      QApplication app(argc, argv);
      // ...
      QFont fon("Helvetica", 40);
      app.setFont(fon);
      
      1 Reply Last reply
      1
      • R Offline
        R Offline
        Rem-Kolomna
        wrote on last edited by
        #3

        Yeah, but this will affect fonts everywhere in application. Can I specify the font in my QQuickWindow only (that is subwindow in mdi area)?

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by A Former User
          #4

          I see no possibility to do it with QQuickWindow, but if you use a QWindow instead and place a QQuickWidget on it then you can use QWidget::setStyleSheet() to set the default font (and maybe other stuff as you like) only for that QQuickWidget.
          :-)

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Rem-Kolomna
            wrote on last edited by
            #5

            Thank you, I will try do it on native window container of my QQuickWindow

            1 Reply Last reply
            0
            • R Rem-Kolomna

              I load my qml scene int QQuickWindow using this code:

              QQmlComponent *comp = new QQmlComponent(engine, 
                QUrl("qrc:/controllers/sample.qml"), contentItem());  
               QObject *obj = comp->create();
               QQmlProperty::write(obj, "parent", QVariant::fromValue<QObject*>(contentItem()));
              

              But font in labels and text fields is small. Is it possible to specify default font in qml?

              p3c0P Offline
              p3c0P Offline
              p3c0
              Moderators
              wrote on last edited by
              #6

              @Rem-Kolomna Did you check FontLoader ? You can add FontLoader in sample.qml to load a particular font and then use it to assign to different elements.

              157

              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
              • Unsolved