Skip to content

Use HiDPI icons for PyQt5 #5057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
except ImportError:
figureoptions = None

from .qt_compat import QtCore, QtGui, QtWidgets, _getSaveFileName, __version__
from .qt_compat import (QtCore, QtGui, QtWidgets, _getSaveFileName,
__version__, is_pyqt5)
from matplotlib.backends.qt_editor.formsubplottool import UiSubplotTool

backend_version = __version__
Expand Down Expand Up @@ -142,6 +143,9 @@ def _create_qApp():
else:
qApp = app

if is_pyqt5():
qApp.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)


class Show(ShowBase):
def mainloop(self):
Expand Down Expand Up @@ -566,6 +570,8 @@ def __init__(self, canvas, parent, coordinates=True):
NavigationToolbar2.__init__(self, canvas)

def _icon(self, name):
if is_pyqt5():
name = name.replace('.png', '_hidpi.png')
return QtGui.QIcon(os.path.join(self.basedir, name))

def _init_toolbar(self):
Expand Down Expand Up @@ -606,6 +612,14 @@ def _init_toolbar(self):
# reference holder for subplots_adjust window
self.adj_window = None

# Esthetic adjustments - we need to set these explicitly in PyQt5
# otherwise the layout looks different - but we don't want to set it if
# not using HiDPI icons otherwise they look worse than before.
if is_pyqt5():
self.setIconSize(QtCore.QSize(24, 24))
self.layout().setSpacing(12)
self.setMinimumHeight(48)

if figureoptions is not None:
def edit_parameters(self):
allaxes = self.canvas.figure.get_axes()
Expand Down
4 changes: 4 additions & 0 deletions lib/matplotlib/backends/qt_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,7 @@ def _getSaveFileName(*args, **kwargs):

'''
QtWidgets = QtGui


def is_pyqt5():
return QT_API == QT_API_PYQT5
Binary file added lib/matplotlib/mpl-data/images/back_hidpi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/matplotlib/mpl-data/images/filesave_hidpi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/matplotlib/mpl-data/images/forward_hidpi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/matplotlib/mpl-data/images/hand_hidpi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/matplotlib/mpl-data/images/home_hidpi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/matplotlib/mpl-data/images/move_hidpi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added lib/matplotlib/mpl-data/images/subplots_hidpi.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.