Reputation: 114
My PyQt application running on MacOS (with a High DPI Retina Display) does not seem to work correctly. For example, the picture below shows a Pixmap size 30x30 (left) next to a manually scaled image (right) via the Preview app (MacOSX default image viewer). Both are visually the same dimensions on my screen, but notice how they have different resolutions - the pixmap on the left has significantly lower quality.
I read here and here that running PyQt 5.10 should be enough to automatically support high DPI displays on MacOS, but from personal research it seems like the application is being rendered at the “normal” resolution and scaled up.
Is there any ideas on how to fix this? I tried setting QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
and QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_DisableHighDpiScaling)
but neither attribute being set seems to be doing anything.
Upvotes: 1
Views: 1440
Reputation: 114
I was able to fix the issue with the low-density, poor resolution pixmaps by inferring the fact that a 30x30 pixmap ought not to be as large as it was on my screen - in the end, I found that I needed to use setDevicePixelRatio(X)
where X
is a float greater than 1.0. See the below example:
# Device pixel ratio must be set AFTER loading the data!
print(pix_map.devicePixelRatio()) # 1.0
pix_map.loadFromData(image_data)
pix_map.setDevicePixelRatio(2.0)
print(pix_map.devicePixelRatio()) # 2.0
Upvotes: 1