PyQt5高清屏幕自适应设置 QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
Qt Designer 设计界面:
在高清屏未设置AA_EnableHighDpiScaling的预览界面:布局字体控件尺寸上明显存在偏差.
设置了AA_EnableHighDpiScaling的预览界面:运行后,与designer界面一致
from PyQt5.QtWidgets import QApplication, QMainWindow, QMessageBox from PyQt5.QtCore import Qt from Ui_mainqt import Ui_MainWindow class MainWindow(QMainWindow, Ui_MainWindow): def __init__(self): super(MainWindow, self).__init__() self.setupUi(self) self.iniConn() if __name__ == '__main__': import sys QApplication.setAttribute(Qt.AA_EnableHighDpiScaling) app = QApplication(sys.argv) formmain = MainWindow() formmain.show() sys.exit(app.exec_())
#####
愿你一寸一寸地攻城略地,一点一点地焕然一新
#####