How to fix buttons not showing properly using Python, PyQt5, and Pyinstaller

前端 未结 1 584
旧巷少年郎
旧巷少年郎 2021-01-28 00:58

I created an interface using Qt Designer and integrated it into my python code using PyQt5. I then created an exe file using Pyinstaller and the interface shows up fine on my la

相关标签:
1条回答
  • 2021-01-28 01:30

    This issue is solved by adding a few more lines of code as shown below. Someone already posted this answer but they deleted it probably thinking its wrong as it took me a while to get back to them with the results, so thank you!

    from PyQt5 import uic, QtWidgets
    import sys
    
    # Enable high DPI scaling
    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)
    app = QtWidgets.QApplication(sys.argv)
    
    window = uic.loadUi('interface.ui')
    window.show()
    
    sys.exit(app.exec_())
    
    0 讨论(0)
提交回复
热议问题