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. How to force font ?
Qt 6.11 is out! See what's new in the release blog

How to force font ?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 1.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.
  • A Offline
    A Offline
    alexzk
    wrote on last edited by
    #1

    I have child widget like this:

    LWidget(QQmlEngine *eng, QWidget *parent = nullptr) :QQuickWidget(eng, parent),

    So I want to know how to setup default font family from C++ side to any loaded QML (which does not have explicit family set) ?

    This test piece from constructor does nothing:

    QFont f = QApplication::font();
    //f.setFamily("Arial");
    f.setFamily("Serto Jerusalem Outline");
    setFont(f);

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alexzk
      wrote on last edited by
      #2

      Solved meself:

      void updateFont(const QString& family, QQuickItem *root)
      {
      QVariant fn = root->property("font");
      if (fn.isValid() && fn.canConvert<QFont>())
      {
      QFont fn2 = fn.value<QFont>();
      fn2.setFamily(family);
      root->setProperty("font", fn2);
      }
      for (const auto& c : root->childItems())
      updateFont(family, c);
      }

      Usage:

      setSource(url);
      updateFont("Serto Jerusalem Outline", rootObject());

      However, it will override any explicit fonts too, but its ok for me.

      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