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

Skip to content

Commit dab05a6

Browse files
committed
Fix loading user-defined icons for Qt plot window
1 parent 04834bc commit dab05a6

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

lib/matplotlib/backends/backend_qt.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,15 @@ def _icon(self, name):
682682
Construct a `.QIcon` from an image file *name*, including the extension
683683
and relative to Matplotlib's "images" data directory.
684684
"""
685-
name = name.replace('.png', '_large.png')
686-
pm = QtGui.QPixmap(str(cbook._get_data_path('images', name)))
685+
# try to find a high-resolution (48x48 px) icon, which we internally
686+
# store with the suffix _large
687+
filepath = cbook._get_data_path('images',
688+
name.replace('.png', '_large.png'))
689+
if not filepath.exists():
690+
# fallback to the given name (in particular also for user icons)
691+
filepath = cbook._get_data_path('images', name)
692+
693+
pm = QtGui.QPixmap(str(filepath))
687694
_setDevicePixelRatio(pm, _devicePixelRatioF(self))
688695
if self.palette().color(self.backgroundRole()).value() < 128:
689696
icon_color = self.palette().color(self.foregroundRole())

0 commit comments

Comments
 (0)