Skip to content

More qt fractional DPI fixes #17640

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

Merged
merged 3 commits into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from . import qt_compat
from .qt_compat import (
QtCore, QtGui, QtWidgets, __version__, QT_API,
_devicePixelRatioF, _isdeleted,
_devicePixelRatioF, _isdeleted, _setDevicePixelRatioF,
)

backend_version = __version__
Expand Down Expand Up @@ -710,7 +710,7 @@ def _icon(self, name):
if QtCore.qVersion() >= '5.':
name = name.replace('.png', '_large.png')
pm = QtGui.QPixmap(str(cbook._get_data_path('images', name)))
qt_compat._setDevicePixelRatio(pm, _devicePixelRatioF(self))
_setDevicePixelRatioF(pm, _devicePixelRatioF(self))
if self.palette().color(self.backgroundRole()).value() < 128:
icon_color = self.palette().color(self.foregroundRole())
mask = pm.createMaskFromColor(QtGui.QColor('black'),
Expand Down
13 changes: 3 additions & 10 deletions lib/matplotlib/backends/qt_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

def _setup_pyqt5():
global QtCore, QtGui, QtWidgets, __version__, is_pyqt5, \
_isdeleted, _devicePixelRatio, _setDevicePixelRatio, _getSaveFileName
_isdeleted, _getSaveFileName

if QT_API == QT_API_PYQT5:
from PyQt5 import QtCore, QtGui, QtWidgets
Expand All @@ -89,14 +89,10 @@ def _isdeleted(obj): return not shiboken2.isValid(obj)
def is_pyqt5():
return True

# self.devicePixelRatio() returns 0 in rare cases
def _devicePixelRatio(obj): return obj.devicePixelRatio() or 1
def _setDevicePixelRatio(obj, factor): obj.setDevicePixelRatio(factor)


def _setup_pyqt4():
global QtCore, QtGui, QtWidgets, __version__, is_pyqt5, \
_isdeleted, _devicePixelRatio, _setDevicePixelRatio, _getSaveFileName
_isdeleted, _getSaveFileName

def _setup_pyqt4_internal(api):
global QtCore, QtGui, QtWidgets, \
Expand Down Expand Up @@ -149,9 +145,6 @@ def _isdeleted(obj): return not shiboken.isValid(obj)
def is_pyqt5():
return False

def _devicePixelRatio(obj): return 1
def _setDevicePixelRatio(obj, factor): pass


if QT_API in [QT_API_PYQT5, QT_API_PYSIDE2]:
_setup_pyqt5()
Expand Down Expand Up @@ -220,6 +213,6 @@ def _setDevicePixelRatioF(obj, val):
if hasattr(obj, 'setDevicePixelRatioF'):
# Not available on Qt<5.6
obj.setDevicePixelRatioF(val)
if hasattr(obj, 'setDevicePixelRatio'):
elif hasattr(obj, 'setDevicePixelRatio'):
# Not available on Qt4 or some older Qt5.
obj.setDevicePixelRatio(val)