How to specify monospace fonts for cross platform Qt applications?

fonts, qt

Solution

You can retrieve the system's default fixed font using QFontDatabase's systemFont(..) function. It was introduced in Qt 5.2.

Example:

const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont)

Problem

Is there a platform independent way to specify a fixed width font for a Qt widget ? If I set the font to "Monospace" in Designer on Linux, it is not found on Windows and Arial is used instead.

Original source