Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to do font arithmetic with QFont in (non ingegral) pixels.
Forum Update on Monday, May 27th 2025

How to do font arithmetic with QFont in (non ingegral) pixels.

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 140 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
    Audetto
    wrote on last edited by
    #1

    I am trying to get a true monospace font on Pi 400, which uses Qt 5.11.3.

    QFont f = QFontDatabase::systemFont(QFontDatabase::FixedFont);
    if(f.styleHint() != QFont::TypeWriter)
    {
        f.setFamily("Monospace"); // Force Monospaced font
        f.setStyleHint(QFont::TypeWriter);
    }
    

    The problem I have is that the conversion pixel <-> point requires rounding.
    In an editor, if one tries to compute where is the n-th character or which character is under the n-th pixel, an integer conversion would be much easier.

    Is there such a thing as a Monospace font with integral (in pixel) size?
    Or can I convert one?

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

      Answering my own question.
      Bite the bullet and use QFontMetricsF and do some rounding where necessary.

      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