如何在 PyQt4 中为 4K 显示器调整 QMenuBar 的大小 [英] How to resize the QMenuBar in PyQt4 for a 4K display

查看:59
本文介绍了如何在 PyQt4 中为 4K 显示器调整 QMenuBar 的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要用 Python 编写一个带有用户界面的应用程序.我决定使用 PyQt4 来制作 GUI.它包含在 Python 的 Anaconda 发行版中.

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.

让 GUI 在 4K 显示器上流畅运行并非易事.默认情况下,大多数组件都太小了.某些组件(例如按钮)很容易调整大小:

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)

但是我如何调整其他组件的大小,比如 QMenuBar?我可以使填充 QMenuBar 的 QMenu 按钮(如文件"、编辑"等)变大吗?我可以让左上角的 WindowTitle 也变大吗?

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?

非常感谢.

推荐答案

您可以更改单个小部件的字体和字体大小.

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.

这篇关于如何在 PyQt4 中为 4K 显示器调整 QMenuBar 的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆