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

Skip to content

Commit 478c49f

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

12 files changed

+20
-1
lines changed

lib/matplotlib/backends/backend_qt5.py

Lines changed: 16 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__
@@ -139,9 +140,13 @@ def _create_qApp():
139140

140141
qApp = QtWidgets.QApplication([six.text_type(" ")])
141142
qApp.lastWindowClosed.connect(qApp.quit)
143+
142144
else:
143145
qApp = app
144146

147+
if is_pyqt5():
148+
qApp.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
149+
145150

146151
class Show(ShowBase):
147152
def mainloop(self):
@@ -566,6 +571,8 @@ def __init__(self, canvas, parent, coordinates=True):
566571
NavigationToolbar2.__init__(self, canvas)
567572

568573
def _icon(self, name):
574+
if is_pyqt5():
575+
name = name.replace('.png', '_hidpi.png')
569576
return QtGui.QIcon(os.path.join(self.basedir, name))
570577

571578
def _init_toolbar(self):
@@ -606,6 +613,14 @@ def _init_toolbar(self):
606613
# reference holder for subplots_adjust window
607614
self.adj_window = None
608615

616+
# Esthetic adjustments - we need to set these explicitly in PyQt5
617+
# otherwise the layout looks different - but we don't want to set it if
618+
# not using HiDPI icons otherwise they look worse than before.
619+
if is_pyqt5():
620+
self.setIconSize(QtCore.QSize(24, 24))
621+
self.layout().setSpacing(12)
622+
self.setMinimumHeight(48)
623+
609624
if figureoptions is not None:
610625
def edit_parameters(self):
611626
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)