我正在开发一种工具,该工具将在不同的计算机上使用,因此会在不同的屏幕分辨率下使用。我尝试了以下代码使我的GUI适应不同的分辨率,但是当尝试不同的分辨率(例如2736 x 1824或800 x 600)时,什么都没有改变:
import sys
import PyQt5
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QPushButton
from frontend_test import Ui_MainWindow
if hasattr(QtCore.Qt, 'AA_EnableHighDpiScaling'):
PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
if hasattr(QtCore.Qt, 'AA_UseHighDpiPixmaps'):
PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)
QT_AUTO_SCREEN_SCALE_FACTOR=1
class Test(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(Test, self).__init__(parent)
self.setupUi(self)
if __name__ == '__main__':
app = QApplication(sys.argv)
prog = Test()
prog.showMaximized()
sys.exit(app.exec_())