[PyQt] PyQt menu and tool tip font

Mark Summerfield mark at qtrac.eu
Sat Oct 25 09:01:39 BST 2008


On 2008-10-24, Thorsten Kampe wrote:
> Hi,
>
> not sure whether this is really a PyQt thing but I'll ask anyway:
>
> PyQt applications (like Sandbox[1]) on Linux have a horrible looking and
> much too small font for the menus, tool tips and for the status bar -
> while on Windows it looks totally normal (like all other applications).
>
> Where or how can I configure the font and the font size for the menus,
> the tool tips and the status bar?!

I have encountered this problem in the past, but not in recent years
with modern Linux distros.

In theory Qt GUI applications accept a -font command line option that
QApplication takes care of. The docs say that this must be in XLFD
format, e.g.,
    ./prog.pyw -font -*-sans\ serif-*-r-*-*-16-*-*-*-*-*-*-*

This approach has the advantage that you don't need access to the
source.

When you create a QApplication object it object "inherits" the user's
preferences for fonts, colours, etc. And all the application's top-level
widgets inherit those properties from QApplication, and all the child
widgets inherit those properties from their parents. So if you set the
font in QApplication, it will affect the whole app. (In the case of
Sandbox.pyw, it will only affect menus and toolbars and similar, since
the program allows the user to override the fonts used for showing
code.)

So you could go to wherever the QApplication instance is created, and on
the next line change the font, e.g.

    app = QApplication(sys.argv)
    app.setFont(QFont("Helvetica", 16))

You can find out what fonts are availabe to Qt using QtGui.QFontDatabase().

-- 
Mark Summerfield, Qtrac Ltd, www.qtrac.eu
    C++, Python, Qt, PyQt - training and consultancy
        "Programming in Python 3" - ISBN 0137129297



More information about the PyQt mailing list