FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

FIX: Qt5 account for dpiratio as early as possible by tacaswell · Pull Request #9002 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (3) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
7 changes: 7 additions & 0 deletions lib/matplotlib/backends/backend_qt5.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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))

Back | FazBrowse Home | New Git URL