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

Skip to content

FIX: Qt5 account for dpiratio as early as possible #9002

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

Merged
merged 2 commits into from
Aug 14, 2017
Merged
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
7 changes: 7 additions & 0 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,13 @@ class FigureCanvasQT(QtWidgets.QWidget, FigureCanvasBase):
# QtCore.Qt.XButton2: None,
}

def _update_figure_dpi(self):
dpi = self._dpi_ratio * self.figure._original_dpi
self.figure._set_dpi(dpi, forward=False)

def __init__(self, figure):
_create_qApp()
figure._original_dpi = figure.dpi

# NB: Using super for this call to avoid a TypeError:
# __init__() takes exactly 2 arguments (1 given) on QWidget
Expand All @@ -192,6 +197,8 @@ def __init__(self, figure):
# http://pyqt.sourceforge.net/Docs/PyQt5/pyqt4_differences.html#cooperative-multi-inheritance
super(FigureCanvasQT, self).__init__(figure=figure)
self.figure = figure
self._update_figure_dpi()

self.setMouseTracking(True)
w, h = self.get_width_height()
self.resize(w, h)
Expand Down
11 changes: 0 additions & 11 deletions lib/matplotlib/backends/backend_qt5agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,6 @@ class FigureCanvasQTAgg(FigureCanvasQTAggBase, FigureCanvasQT):

"""

def __init__(self, figure):
super(FigureCanvasQTAgg, self).__init__(figure=figure)
# We don't want to scale up the figure DPI more than once.
# Note, we don't handle a signal for changing DPI yet.
self.figure._original_dpi = self.figure.dpi
self._update_figure_dpi()

def _update_figure_dpi(self):
dpi = self._dpi_ratio * self.figure._original_dpi
self.figure._set_dpi(dpi, forward=False)


@_BackendQT5.export
class _BackendQT5Agg(_BackendQT5):
Expand Down
9 changes: 5 additions & 4 deletions lib/matplotlib/tests/test_backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def test_dpi_ratio_change():
size = qt_canvas.size()

qt_canvas.manager.show()
qt_canvas.draw()
qApp.processEvents()

# The DPI and the renderer width/height change
Expand All @@ -133,8 +134,8 @@ def test_dpi_ratio_change():
assert qt_canvas.renderer.height == 720

# The actual widget size and figure physical size don't change
assert size.width() == 200
assert size.height() == 80
assert size.width() == 600
assert size.height() == 240
assert_equal(qt_canvas.get_width_height(), (600, 240))
assert_equal(fig.get_size_inches(), (5, 2))

Expand All @@ -151,7 +152,7 @@ def test_dpi_ratio_change():
assert qt_canvas.renderer.height == 480

# The actual widget size and figure physical size don't change
assert size.width() == 200
assert size.height() == 80
assert size.width() == 600
assert size.height() == 240
assert_equal(qt_canvas.get_width_height(), (600, 240))
assert_equal(fig.get_size_inches(), (5, 2))