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

Skip to content

Commit cedaaae

Browse files
committed
MNT: tweak the toolbar for Qt
Do not over-size the icons
1 parent 9ba3c21 commit cedaaae

File tree

1 file changed

+5
-19
lines changed

1 file changed

+5
-19
lines changed

lib/matplotlib/backends/backend_qt5.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,9 @@ def __init__(self, canvas, parent, coordinates=True):
592592
def _icon(self, name):
593593
if is_pyqt5():
594594
name = name.replace('.png', '_large.png')
595-
return QtGui.QIcon(os.path.join(self.basedir, name))
595+
pm = QtGui.QPixmap(os.path.join(self.basedir, name))
596+
pm.setDevicePixelRatio(self.canvas._dpi_ratio)
597+
return QtGui.QIcon(pm)
596598

597599
def _init_toolbar(self):
598600
self.basedir = os.path.join(matplotlib.rcParams['datapath'], 'images')
@@ -602,7 +604,7 @@ def _init_toolbar(self):
602604
self.addSeparator()
603605
else:
604606
a = self.addAction(self._icon(image_file + '.png'),
605-
text, getattr(self, callback))
607+
text, getattr(self, callback))
606608
self._actions[callback] = a
607609
if callback in ['zoom', 'pan']:
608610
a.setCheckable(True)
@@ -624,29 +626,13 @@ def _init_toolbar(self):
624626
QtCore.Qt.AlignRight | QtCore.Qt.AlignTop)
625627
self.locLabel.setSizePolicy(
626628
QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding,
627-
QtWidgets.QSizePolicy.Ignored))
629+
QtWidgets.QSizePolicy.Ignored))
628630
labelAction = self.addWidget(self.locLabel)
629631
labelAction.setVisible(True)
630632

631633
# reference holder for subplots_adjust window
632634
self.adj_window = None
633635

634-
# Esthetic adjustments - we need to set these explicitly in PyQt5
635-
# otherwise the layout looks different - but we don't want to set it if
636-
# not using HiDPI icons otherwise they look worse than before.
637-
if is_pyqt5():
638-
self.setIconSize(QtCore.QSize(24, 24))
639-
self.layout().setSpacing(12)
640-
641-
if is_pyqt5():
642-
# For some reason, self.setMinimumHeight doesn't seem to carry over to
643-
# the actual sizeHint, so override it instead in order to make the
644-
# aesthetic adjustments noted above.
645-
def sizeHint(self):
646-
size = super(NavigationToolbar2QT, self).sizeHint()
647-
size.setHeight(max(48, size.height()))
648-
return size
649-
650636
def edit_parameters(self):
651637
allaxes = self.canvas.figure.get_axes()
652638
if not allaxes:

0 commit comments

Comments
 (0)