tags:

views:

635

answers:

3

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.

+1  A: 

For all widgets that accept Rich Text you can simply put it into a pre block, i.e. <pre>This is my Text</pre>. It will then use the systems monospace font.

bluebrother
A: 

I use Courier in Qt on both Linux and Windows.

Pete
+2  A: 

You can use the style hint property of QFont:

QFont font("Monospace");
font.setStyleHint(QFont::TypeWriter);

If the font cannot be found (which happens with Monospace on Windows), Qt's font matching algorithm tries to find a font that matches the given style hint.

Torsten Marek