Skip to content

Commit e9ccf4d

Browse files
committed
Use HiDPI icons for PyQt5
1 parent b9bc7d1 commit e9ccf4d

12 files changed

+20
-1
lines changed

lib/matplotlib/backends/backend_qt5.py

+16-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
except ImportError:
2929
figureoptions = None
3030

31-
from .qt_compat import QtCore, QtGui, QtWidgets, _getSaveFileName, __version__
31+
from .qt_compat import QtCore, QtGui, QtWidgets, _getSaveFileName, __version__, is_pyqt5
3232
from matplotlib.backends.qt_editor.formsubplottool import UiSubplotTool
3333

3434
backend_version = __version__
@@ -139,9 +139,13 @@ def _create_qApp():
139139

140140
qApp = QtWidgets.QApplication([six.text_type(" ")])
141141
qApp.lastWindowClosed.connect(qApp.quit)
142+
142143
else:
143144
qApp = app
144145

146+
if is_pyqt5():
147+
qApp.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps);
148+
145149

146150
class Show(ShowBase):
147151
def mainloop(self):
@@ -566,6 +570,8 @@ def __init__(self, canvas, parent, coordinates=True):
566570
NavigationToolbar2.__init__(self, canvas)
567571

568572
def _icon(self, name):
573+
if is_pyqt5():
574+
name = name.replace('.png', '_hidpi.png')
569575
return QtGui.QIcon(os.path.join(self.basedir, name))
570576

571577
def _init_toolbar(self):
@@ -605,6 +611,15 @@ def _init_toolbar(self):
605611

606612
# reference holder for subplots_adjust window
607613
self.adj_window = None
614+
615+
# Esthetic adjustments - we need to set these explicitly in PyQt5
616+
# otherwise the layout looks different - but we don't want to set it if
617+
# not using HiDPI icons otherwise they look worse than before.
618+
if is_pyqt5():
619+
self.setIconSize(QtCore.QSize(24,24))
620+
self.layout().setSpacing(12)
621+
self.setMinimumHeight(48)
622+
608623

609624
if figureoptions is not None:
610625
def edit_parameters(self):

lib/matplotlib/backends/qt_compat.py

+4
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,7 @@ def _getSaveFileName(*args, **kwargs):
150150
151151
'''
152152
QtWidgets = QtGui
153+
154+
155+
def is_pyqt5():
156+
return QT_API == QT_API_PYQT5
3.42 KB
Loading
Loading
3.49 KB
Loading
2.07 KB
Loading
Loading
Loading
1.41 KB
Loading
Loading
Loading

0 commit comments

Comments
 (0)