-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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
Conversation
Confirmed that this Fixes #30218 |
# 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( |
There was a problem hiding this comment.
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
# 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( |
There was a problem hiding this comment.
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.
97c3be7
to
a23bb28
Compare
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
Note, I think we don't need the |
if current_version >= (6, 6): | ||
window.installEventFilter(self) | ||
else: | ||
window.screenChanged.connect(self._update_screen) | ||
self._update_screen(window.screen()) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
…o refresh scaling
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? |
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. |
…345-on-v3.10.x Backport PR #30345 on branch v3.10.x (qt: Use better devicePixelRatio event to refresh scaling)
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