From 1b9538f6bb8610870de89a6b84e2cf06a0de548e Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Wed, 17 Jul 2019 02:11:43 +0200 Subject: [PATCH] Lighten icons of NavigationToolbar2QT on dark-themes --- lib/matplotlib/backends/backend_qt5.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/backends/backend_qt5.py b/lib/matplotlib/backends/backend_qt5.py index 19dca99ce743..5525fab34418 100644 --- a/lib/matplotlib/backends/backend_qt5.py +++ b/lib/matplotlib/backends/backend_qt5.py @@ -670,22 +670,32 @@ def __init__(self, canvas, parent, coordinates=True): QtWidgets.QToolBar.__init__(self, parent) NavigationToolbar2.__init__(self, canvas) - def _icon(self, name): + def _icon(self, name, color=None): if is_pyqt5(): name = name.replace('.png', '_large.png') pm = QtGui.QPixmap(os.path.join(self.basedir, name)) if hasattr(pm, 'setDevicePixelRatio'): pm.setDevicePixelRatio(self.canvas._dpi_ratio) + if color is not None: + mask = pm.createMaskFromColor(QtGui.QColor('black'), + QtCore.Qt.MaskOutColor) + pm.fill(color) + pm.setMask(mask) return QtGui.QIcon(pm) def _init_toolbar(self): self.basedir = str(cbook._get_data_path('images')) + background_color = self.palette().color(self.backgroundRole()) + foreground_color = self.palette().color(self.foregroundRole()) + icon_color = (foreground_color + if background_color.value() < 128 else None) + for text, tooltip_text, image_file, callback in self.toolitems: if text is None: self.addSeparator() else: - a = self.addAction(self._icon(image_file + '.png'), + a = self.addAction(self._icon(image_file + '.png', icon_color), text, getattr(self, callback)) self._actions[callback] = a if callback in ['zoom', 'pan']: @@ -693,7 +703,8 @@ def _init_toolbar(self): if tooltip_text is not None: a.setToolTip(tooltip_text) if text == 'Subplots': - a = self.addAction(self._icon("qt4_editor_options.png"), + a = self.addAction(self._icon("qt4_editor_options.png", + icon_color), 'Customize', self.edit_parameters) a.setToolTip('Edit axis, curve and image parameters')