-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Support fractional HiDpi scaling with Qt backends #15656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -185,7 +185,41 @@ def _setDevicePixelRatio(obj, factor): pass | |
# These globals are only defined for backcompatibility purposes. | ||
ETS = dict(pyqt=(QT_API_PYQTv2, 4), pyside=(QT_API_PYSIDE, 4), | ||
pyqt5=(QT_API_PYQT5, 5), pyside2=(QT_API_PYSIDE2, 5)) | ||
|
||
QT_RC_MAJOR_VERSION = int(QtCore.qVersion().split(".")[0]) | ||
|
||
if QT_RC_MAJOR_VERSION == 4: | ||
mpl.cbook.warn_deprecated("3.3", name="support for Qt4") | ||
|
||
|
||
def _devicePixelRatioF(obj): | ||
""" | ||
Return obj.devicePixelRatioF() with graceful fallback for older Qt. | ||
|
||
This can be replaced by the direct call when we require Qt>=5.6. | ||
""" | ||
try: | ||
# Not available on Qt<5.6 | ||
return obj.devicePixelRatioF() or 1 | ||
except AttributeError: | ||
pass | ||
try: | ||
# Not available on Qt4 or some older Qt5. | ||
# self.devicePixelRatio() returns 0 in rare cases | ||
return obj.devicePixelRatio() or 1 | ||
except AttributeError: | ||
return 1 | ||
|
||
|
||
def _setDevicePixelRatioF(obj, val): | ||
""" | ||
Call obj.setDevicePixelRatioF(val) with graceful fallback for older Qt. | ||
|
||
This can be replaced by the direct call when we require Qt>=5.6. | ||
""" | ||
if hasattr(obj, 'setDevicePixelRatioF'): | ||
# Not available on Qt<5.6 | ||
obj.setDevicePixelRatioF(val) | ||
if hasattr(obj, 'setDevicePixelRatio'): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I opened #17640 with this change. |
||
# Not available on Qt4 or some older Qt5. | ||
obj.setDevicePixelRatio(val) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want to cast to int here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would think so, given your other Qt PR, though that's for new Qt that wouldn't call this. Though I think it would come from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to use
round
here rather thanint
to move the jumps away from the integers.However, this may have issues with not being in sync with what we do else were in the code (which is
int
).