How to resize the QMenuBar in PyQt4 for a 4K displ

2020-04-21 06:51发布

问题:

I need to write an application in Python with a User Interface. I decided to go for PyQt4 to make the GUI. It is included in the Anaconda distribution of Python.

To make a GUI running smoothly on a 4K display is not trivial. Most components are way too small by default. Some components - like buttons - are easy to resize:

btn = QtGui.QPushButton("Quit", self)
btn.resize(100,100)

But how do I resize other components, like the QMenuBar? Can I make the QMenu buttons (Like "File", "Edit", ..) that populate the QMenuBar larger? Can I make the WindowTitle in the top left corner also larger?

Thank you very much.

回答1:

You can change the font and font-size of individual widgets.

font = self.menuBar().font()
font.setPointSize(20)
self.menuBar().setFont(font)

But typically something like this would be handled by your OS/window manager. I'm assuming all your other applications have text that looks just as small? For high-res displays, most popular OS's have scaling features to emulate the size of a lower resolution monitor.