Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Example

like image 992
Lucidnonsense Avatar asked Aug 31 '16 10:08

Lucidnonsense


People also ask

Is PyQt good for GUI?

PyQt5 is a very well-known GUI framework used by both Python coders and UI designers. One of its components, the PyQt package, is built around the Qt framework, which is a leading cross-platform GUI design tool for just about any kind of application.

Is PyQt good for desktop application?

Compared to Electron and JavaScript, PyQt5 might not be the popular tool to build desktop apps, but it's very effective. Web apps are very popular, but there are still times when only a desktop app can deliver a great user experience.

Should I use PySide or PyQt?

Advantages of PySide PySide represents the official set of Python bindings backed up by the Qt Company. PySide comes with a license under the LGPL, meaning it is simpler to incorporate into commercial projects when compared with PyQt. It allows the programmer to use QtQuick or QML to establish the user interface.

What IDE should I use for PyQt?

Wing Pro is a Python IDE that can be used to develop, test, and debug Python code written for the PyQt cross-platform GUI development toolkit.


1 Answers

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

like image 191
Storm Shadow Avatar answered Oct 13 '22 05:10

Storm Shadow