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. Fonts render to integer widths on some platforms, render to real number on others

Fonts render to integer widths on some platforms, render to real number on others

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
fontmonospacewidth
1 Posts 1 Posters 253 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
    Alpheratz
    wrote on 17 Jun 2021, 11:48 last edited by
    #1

    Hello,

    I've been trying to obtain a monospace font which renders to the same width per letter on any platform, measured in pixels. My current approach is to load a TrueType font and set a pixelWidth, like so:

    main.qml:

    Text {
    	id: mytext
    	text: 'a'
    	font.pixelSize: 18
    }
    Text {
    	id: widthmeasurement
    	text: mytext.width
    }
    

    main.cpp:

    QApplication app(argc, argv);
    QFontDatabase::addApplicationFont("TheFont.ttf");
    QFont font("TheFont");
    app.setFont(font);
    

    The issue is that on one platform (Win10), the width of each character is rounded to the next integer. On the other platform (Ubuntu 18.04), the width of each character is a real number. The result is an inconsistent text width between platforms.

    How can I get around this issue? Is there a setting to force integer widths for characters?

    Thank you!

    1 Reply Last reply
    0

    1/1

    17 Jun 2021, 11:48

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved