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 e9b83ef

Browse files
Merge pull request matplotlib#30428 from meeseeksmachine/auto-backport-of-pr-30399-on-v3.10.x
Backport PR matplotlib#30399 on branch v3.10.x (Qt: Fix HiDPI handling on X11/Windows)
2 parents e52c3ea + 5043b5a commit e9b83ef

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
@@ -175,45 +175,30 @@ def set_device_pixel_ratio(ratio):
175175
assert qt_canvas.device_pixel_ratio == ratio
176176

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

218203

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

0 commit comments

Comments
(0)

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