Important: Please read the Qt Code of Conduct -

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

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


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


    QApplication app(argc, argv);
    QFont font("TheFont");

    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!

Log in to reply