我正在运行Windows 10并使用PyQt5(Python 3.6,来自anaconda的Qt5.6)。我有两台显示器,一台HD缩放为100%,另一台4K显示器缩放为150%。我有一个简单的GUI示例如下所示。除标题栏外,所有内容都会缩放。想知道如何解决这个问题。请参阅以下两种分辨率的图像。
import sys
from PyQt5 import QtGui, QtCore, QtWidgets
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
app = QtWidgets.QApplication([])
window = QtWidgets.QMainWindow()
window.setWindowTitle("Hello World")
fileMenu = QtWidgets.QMenu("File", window)
longMenu = QtWidgets.QMenu("Long Menu Title", window)
window.menuBar().addMenu(fileMenu)
window.menuBar().addMenu(longMenu)
window.show()
sys.exit(app.exec_())
回答以下答案:
根据下面的答案设置window.font()属性会更改菜单字体,但不会影响窗口标题栏字体。以下代码在下图中生成结果:
import sys
from PyQt5 import QtGui, QtCore, QtWidgets
QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
app = QtWidgets.QApplication([])
window = QtWidgets.QMainWindow()
window.setWindowTitle("Hello World")
fileMenu = QtWidgets.QMenu("File", window)
longMenu = QtWidgets.QMenu("Long Menu Title", window)
window.menuBar().addMenu(fileMenu)
window.menuBar().addMenu(longMenu)
font = window.font()
font.setPointSize(12)
window.setFont(font) # set font here
window.show()
sys.exit(app.exec_())
答案 0 :(得分:0)
应该使用[...document.querySelectorAll(".your-element")].forEach( el =>
VanillaTilt.init(el, {max: 25, speed: 400})
);
,其中x = 12,如下面的代码所示。另见内联评论。
font.setPointSize(x)