|
17 | 17 | from matplotlib.backend_managers import ToolManager
|
18 | 18 |
|
19 | 19 | from .qt_compat import (
|
20 |
| - QtCore, QtGui, QtWidgets, _getSaveFileName, is_pyqt5, __version__, QT_API) |
| 20 | + QtCore, QtGui, QtWidgets, _getSaveFileName, is_pyqt5, __version__, QT_API, |
| 21 | + _devicePixelRatioF, _setDevicePixelRatioF) |
21 | 22 |
|
22 | 23 | backend_version = __version__
|
23 | 24 |
|
@@ -260,12 +261,7 @@ def _update_figure_dpi(self):
|
260 | 261 |
|
261 | 262 | @property
|
262 | 263 | def _dpi_ratio(self):
|
263 |
| - # Not available on Qt4 or some older Qt5. |
264 |
| - try: |
265 |
| - # self.devicePixelRatio() returns 0 in rare cases |
266 |
| - return self.devicePixelRatio() or 1 |
267 |
| - except AttributeError: |
268 |
| - return 1 |
| 264 | + return _devicePixelRatioF(self) |
269 | 265 |
|
270 | 266 | def _update_dpi(self):
|
271 | 267 | # As described in __init__ above, we need to be careful in cases with
|
@@ -683,8 +679,7 @@ def _icon(self, name, color=None):
|
683 | 679 | if is_pyqt5():
|
684 | 680 | name = name.replace('.png', '_large.png')
|
685 | 681 | pm = QtGui.QPixmap(os.path.join(self.basedir, name))
|
686 |
| - if hasattr(pm, 'setDevicePixelRatio'): |
687 |
| - pm.setDevicePixelRatio(self.canvas._dpi_ratio) |
| 682 | + _setDevicePixelRatioF(pm, self.canvas._dpi_ratio) |
688 | 683 | if color is not None:
|
689 | 684 | mask = pm.createMaskFromColor(QtGui.QColor('black'),
|
690 | 685 | QtCore.Qt.MaskOutColor)
|
@@ -957,8 +952,7 @@ def _add_to_group(self, group, name, button, position):
|
957 | 952 |
|
958 | 953 | def _icon(self, name):
|
959 | 954 | pm = QtGui.QPixmap(name)
|
960 |
| - if hasattr(pm, 'setDevicePixelRatio'): |
961 |
| - pm.setDevicePixelRatio(self.toolmanager.canvas._dpi_ratio) |
| 955 | + _setDevicePixelRatioF(pm, self.toolmanager.canvas._dpi_ratio) |
962 | 956 | return QtGui.QIcon(pm)
|
963 | 957 |
|
964 | 958 | def toggle_toolitem(self, name, toggled):
|
|
0 commit comments