Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1a755dd

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

12 files changed

+19
-1
lines changed

lib/matplotlib/backends/backend_qt5.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
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,
32+
__version__, is_pyqt5)
3233
from matplotlib.backends.qt_editor.formsubplottool import UiSubplotTool
3334

3435
backend_version = __version__
@@ -142,6 +143,9 @@ def _create_qApp():
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):
@@ -606,6 +612,14 @@ def _init_toolbar(self):
606612
# reference holder for subplots_adjust window
607613
self.adj_window = None
608614

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+
609623
if figureoptions is not None:
610624
def edit_parameters(self):
611625
allaxes = self.canvas.figure.get_axes()

lib/matplotlib/backends/qt_compat.py

Lines changed: 4 additions & 0 deletions
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)