Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt Quick for Android, font customisation
Forum Updated to NodeBB v4.3 + New Features

Qt Quick for Android, font customisation

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
2 Posts 1 Posters 155 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.
  • B Offline
    B Offline
    Bad_man
    wrote on last edited by
    #1

    May anyone to give a hint with embedding custom font style?
    the thing is it works without any problem on Windows, but starting android emu, it returns to basic font.
    I need only to use it to customize title and few lines of my app.

    I tried to use fontloader, truth to be told, it does not help
    maybe some one has relevant example for nowadays 2024, cause look's like all font's issues were discussed on Stackowerflow 10 years ago.
    no any relevant information.
    I upgraded qt up to the last version, it did not help.
    thank you for ideas and hints in advance

    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bad_man
      wrote on last edited by Bad_man
      #2

      embedded this code into main.cpp to see, would it change behavior or not
      int fontId = QFontDatabase::addApplicationFont("qrc:/assets/fonts/Expansiva.otf");

      QStringList availableFonts = QFontDatabase::families();
      
      if (fontId == -1) {
          qDebug() << "Error: Failed to load custom font from resource.";
      } else {
          QStringList fontFamilies = QFontDatabase::applicationFontFamilies(fontId);
          if (fontFamilies.isEmpty()) {
              qDebug() << "Error: No font families loaded.";
          } else {
              qDebug() << "Font family loaded successfully: " << fontFamilies.first();
              // Step 2: Set the font style (font family, size, and optional weight or style)
              QFont customFont;
              customFont.setFamily(fontFamilies.first());  // Use the loaded font's family name
              customFont.setPointSize(12);  // Set desired font size
              customFont.setBold(true);     // Make the font bold (optional)
              customFont.setItalic(false);  // Set italic (optional)
              // Step 3: Apply the custom font globally
              app.setFont(customFont);
          }
      }
      

      this address does not provide access to font file:

      "qrc:/assets/fonts/Expansiva.otf"
      

      this, yes: ```
      "calc_salary/fonts/Expansiva.otf"

      
      resource.qrc looks like
      

      <RCC>
      <qresource prefix="/assets">
      <file>fonts/Expansiva.otf</file>
      <file>fonts/ExpansivaBold.otf</file>
      <file>fonts/ExpansivaBoldItalic.otf</file>
      <file>fonts/ExpansivaItalic.otf</file>
      <file>fonts/ArtsyNight.otf</file>
      <file>fonts/ROSEMERO.ttf</file>
      </qresource>
      </RCC>

      
      is it right or not, smart people has to estimate it
      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