'PyQt GUI size on high resolution screens
I posted a question a while ago asking about Tkinter backends and subsequently forgot about it but I've since realised that I'm using the pyqt backend. Is there a fix for that?
Original Question:
So it appears that matplotlib gui plots (a la plt.show()) don't adapt to monitor resolution and appear tiny on high resolution screens. Is there a matplotlib+Pyqt fix or do I have fiddle around somewhere in Windows settings?
Thanks
Solution 1:[1]
Before app is loaded, and not while loading.
insert:
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)
like so :
import PyQt5
from PyQt5 import QtCore, QtGui, uic, QtWidgets
from PyQt5.QtWidgets import QWidget
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)
class MyWindow(PyQt5.QtWidgets.QMainWindow):
def __init__(self):
super(MyWindow, self).__init__()
And if that still don't work, in user en var and not system en var.
QT_AUTO_SCREEN_SCALE_FACTOR=2
Solution 2:[2]
While I do not have much experience with PyQt, upon googling I found this SO question about setting the window state of a PyQT window to maximised. The accepted answer says to use self.showMaximized()
to do so.
Solution 3:[3]
For python this worked for me:
if hasattr(Qt, 'AA_EnableHighDpiScaling'):
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
if hasattr(Qt, 'AA_UseHighDpiPixmaps'):
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps, True)
if __name__ == '__main__':
app = QApplication(sys.argv)
print(f"Using AA_EnableHighDpiScaling > {QApplication.testAttribute(Qt.AA_EnableHighDpiScaling)}")
print(f"Using AA_UseHighDpiPixmaps > {QApplication.testAttribute(Qt.AA_UseHighDpiPixmaps)}")
# your window here
app.exec()
based on this answer: https://stackoverflow.com/a/56140241/9525238
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Storm Shadow |
Solution 2 | Community |
Solution 3 |