6

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

Example

Community
  • 1
  • 1
Lucidnonsense
  • 1,195
  • 3
  • 13
  • 35

3 Answers3

18

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 

qt-5/highdpi

Storm Shadow
  • 442
  • 5
  • 12
  • In case I start my app on a high DPI screen the solution works fine. In case I start the app on a low DPI screen the app window size is bigger and resized to the correct size after the application window has been moved with the mouse only. How ca I fix this? – thinwybk Oct 21 '19 at 10:23
  • 1
    ... I had the minimumSize and maximumSize for width and height set to equal values to get a fiexed size app window. If I reset these properties in QtDesigner to the defaults the app windows are resized the right way. How can I prevent users from app window resizing now? – thinwybk Oct 21 '19 at 10:28
0

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.

Community
  • 1
  • 1
Koga
  • 523
  • 4
  • 13
  • 1
    That just maximises the window, not change the size of the gui elements/text etc. Now the window is just bigger – Lucidnonsense Aug 31 '16 at 10:57
  • @Lucidnonsense Maybe this might help. http://stackoverflow.com/questions/406939/pyqt-getting-widgets-to-resize-automatically-in-a-qdialog – Koga Aug 31 '16 at 10:59
0

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

Andrei M.
  • 313
  • 2
  • 10