Skip to content

qt: Use better devicePixelRatio event to refresh scaling #30345

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 1 commit into from
Jul 24, 2025

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Jul 23, 2025

PR summary

With Qt 6.6, there is an event on the window that signals when the devicePixelRatio has changed. This is better than before when we had to rely on the underlying QScreen, which doesn't correctly refresh when a fractional scale is used.

Fixes #30218

PR checklist

@QuLogic QuLogic added this to the v3.10.4 milestone Jul 23, 2025
@tacaswell
Copy link
Member

Confirmed that this Fixes #30218

Comment on lines 160 to 162
# Emitting this event is simply to trigger the DPI change handler
# in Matplotlib in the same manner that it would occur normally.
qt_canvas.eventFilter(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is calling eventFilter() the standard way to emit a self-created event? This feels a bit hacky, which may be ok. But I'd rathe comment like this

Suggested change
# Emitting this event is simply to trigger the DPI change handler
# in Matplotlib in the same manner that it would occur normally.
qt_canvas.eventFilter(
# Create an event to explicitly trigger the DPI change handler.
# We push the event into Qt's event handling system by injecting it into
# the eventFilter
qt_canvas.eventFilter(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just copied the old form, but we can push an event normally.

@QuLogic QuLogic force-pushed the qt-better-hidpi branch 2 times, most recently from 97c3be7 to a23bb28 Compare July 23, 2025 21:06
With Qt 6.6, there is an event on the window that signals when the
devicePixelRatio has changed. This is better than before when we had to
rely on the underlying `QScreen`, which doesn't correctly refresh when a
fractional scale is used.

Fixes matplotlib#30218
@QuLogic
Copy link
Member Author

QuLogic commented Jul 23, 2025

Note, I think we don't need the qt_core fixture any more, but since this is going to 3.10.4, I was going to leave removing that to a separate PR for 3.11.

Comment on lines +275 to +279
if current_version >= (6, 6):
window.installEventFilter(self)
else:
window.screenChanged.connect(self._update_screen)
self._update_screen(window.screen())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suspect that both cases are a bit sloppy in that they connect/install on every showEvent. We typically have one, but there may be cases where the window lives longer and is hidden/shown multiple times. At least for connect() multiple calls result in multiple connections, i.e. firing multiple times.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

atleast for the event filter version

If filterObj has already been installed for this object, this function moves it so it acts as if it was installed last.

so it is OK to install it multiple times.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I could find a better event just yet, but I'll try to take a look again later.

Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@QuLogic can self merge if he would like to deal with note about possible multiple connections in a follow on PR.

@QuLogic QuLogic merged commit 93ed6de into matplotlib:main Jul 24, 2025
40 checks passed
@QuLogic QuLogic deleted the qt-better-hidpi branch July 24, 2025 18:45
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jul 24, 2025
@cbrnr
Copy link
Contributor

cbrnr commented Jul 24, 2025

Thank you 🔥! So happy to get nice looking Matplotlib plots now! I haven't tested it though, when will this fix be available in a release?

@tacaswell
Copy link
Member

We are going to do a 3.10.4 this week (mostly to the fix for py3.14 released) so this made it in under the wire.

ksunden added a commit that referenced this pull request Jul 25, 2025
…345-on-v3.10.x

Backport PR #30345 on branch v3.10.x (qt: Use better devicePixelRatio event to refresh scaling)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Rendering on Wayland with fractional scaling looks bad
4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy