Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 77a16b9

Browse files
authored
Merge pull request matplotlib#30399 from QuLogic/fix-qt-x-hidpi
Qt: Fix HiDPI handling on X11/Windows
2 parents 5f9c640 + a99b99d commit 77a16b9

File tree

2 files changed

+24
-38
lines changed

2 files changed

+24
-38
lines changed

‎lib/matplotlib/backends/backend_qt.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ def showEvent(self, event):
273273
window = self.window().windowHandle()
274274
current_version = tuple(int(x) for x in QtCore.qVersion().split('.', 2)[:2])
275275
if current_version >= (6, 6):
276+
self._update_pixel_ratio()
276277
window.installEventFilter(self)
277278
else:
278279
window.screenChanged.connect(self._update_screen)

‎lib/matplotlib/tests/test_backend_qt.py

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -169,45 +169,30 @@ def set_device_pixel_ratio(ratio):
169169
assert qt_canvas.device_pixel_ratio == ratio
170170

171171
qt_canvas.manager.show()
172+
qt_canvas.draw()
173+
qt_canvas.flush_events()
172174
size = qt_canvas.size()
173-
set_device_pixel_ratio(3)
174-
175-
# The DPI and the renderer width/height change
176-
assert fig.dpi == 360
177-
assert qt_canvas.renderer.width == 1800
178-
assert qt_canvas.renderer.height == 720
179-
180-
# The actual widget size and figure logical size don't change.
181-
assert size.width() == 600
182-
assert size.height() == 240
183-
assert qt_canvas.get_width_height() == (600, 240)
184-
assert (fig.get_size_inches() == (5, 2)).all()
185-
186-
set_device_pixel_ratio(2)
187-
188-
# The DPI and the renderer width/height change
189-
assert fig.dpi == 240
190-
assert qt_canvas.renderer.width == 1200
191-
assert qt_canvas.renderer.height == 480
192-
193-
# The actual widget size and figure logical size don't change.
194-
assert size.width() == 600
195-
assert size.height() == 240
196-
assert qt_canvas.get_width_height() == (600, 240)
197-
assert (fig.get_size_inches() == (5, 2)).all()
198-
199-
set_device_pixel_ratio(1.5)
200-
201-
# The DPI and the renderer width/height change
202-
assert fig.dpi == 180
203-
assert qt_canvas.renderer.width == 900
204-
assert qt_canvas.renderer.height == 360
205-
206-
# The actual widget size and figure logical size don't change.
207-
assert size.width() == 600
208-
assert size.height() == 240
209-
assert qt_canvas.get_width_height() == (600, 240)
210-
assert (fig.get_size_inches() == (5, 2)).all()
175+
176+
options = [
177+
(None, 360, 1800, 720), # Use ratio at startup time.
178+
(3, 360, 1800, 720), # Change to same ratio.
179+
(2, 240, 1200, 480), # Change to different ratio.
180+
(1.5, 180, 900, 360), # Fractional ratio.
181+
]
182+
for ratio, dpi, width, height in options:
183+
if ratio is not None:
184+
set_device_pixel_ratio(ratio)
185+
186+
# The DPI and the renderer width/height change
187+
assert fig.dpi == dpi
188+
assert qt_canvas.renderer.width == width
189+
assert qt_canvas.renderer.height == height
190+
191+
# The actual widget size and figure logical size don't change.
192+
assert size.width() == 600
193+
assert size.height() == 240
194+
assert qt_canvas.get_width_height() == (600, 240)
195+
assert (fig.get_size_inches() == (5, 2)).all()
211196

212197

213198
@pytest.mark.backend('QtAgg', skip_on_importerror=True)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /