Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
tacaswell commentedJul 23, 2025
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 toa23bb28CompareWith Qt 6.6, there is an event on the window that signals when thedevicePixelRatio has changed. This is better than before when we had torely on the underlying `QScreen`, which doesn't correctly refresh when afractional scale is used.Fixesmatplotlib#30218
QuLogic commentedJul 23, 2025
Note, I think we don't need the |
| ifcurrent_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 forconnect() 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.
tacaswell left a comment
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.
93ed6de intomatplotlib:mainUh oh!
There was an error while loading.Please reload this page.
cbrnr commentedJul 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 commentedJul 24, 2025
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.xBackport PR#30345 on branch v3.10.x (qt: Use better devicePixelRatio event to refresh scaling)
cgohlke commentedAug 3, 2025
cbrnr commentedAug 3, 2025
I will test this tomorrow on Wayland... |


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