Skip to content

Qt IconEngine: Use a device pixel ratio of 1 when high-DPI pixmaps are disabled - #32221

Merged
timhoffm merged 1 commit into
matplotlib:mainfrom
iccir:fix-qt5-toolbar-icons
Aug 19, 2026
Merged

Qt IconEngine: Use a device pixel ratio of 1 when high-DPI pixmaps are disabled#32221
timhoffm merged 1 commit into
matplotlib:mainfrom
iccir:fix-qt5-toolbar-icons

Conversation

@iccir

@iccir iccir commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

PR summary

On Qt5, if the QApplication instance has an AA_UseHighDpiPixmaps attribute set to false, our _IconEngine will return icons that are too large.

Check this attribute and return 1 for _IconEngine._devicePixelRatio() if high DPI pixmaps are disabled.

This attribute is always true on Qt6.

Closes #32217

AI Disclosure

I used AI to help me write a test reduction for #32217. I used AI to help me clean up the resulting implementation.

PR quality check

  • Use an expressive title, e.g. "Fix title font property precedence"
  • New and changed code is tested Tested manually, I don't know how to automate this.
  • [N/A] Plotting related features are demonstrated in an example
  • [N/A] New features and API changes have release notes
  • [N/A] Documentation complies with general and docstring guidelines

@iccir iccir changed the title Qt IconManager: Use a device pixel ratio of 1 when high-DPI pixmaps are disabled Qt IconEngine: Use a device pixel ratio of 1 when high-DPI pixmaps are disabled Aug 16, 2026
@timhoffm

Copy link
Copy Markdown
Member

I suspect we are using devicePixelRatio() also for other sizes like canvas/window size and event locations. Would those aspects not break when changing the behavior of devicePixelRatio()?

@iccir

iccir commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

I suspect we are using devicePixelRatio() also for other sizes like canvas/window size and event locations. Would those aspects not break when changing the behavior of devicePixelRatio()?

This only modifies _IconEngine._devicePixelRatio(). As far as I can tell, this is only used to scale the size of the QPixMap and also is set as its devicePixelRatio:

dpr = self._devicePixelRatio()
scaled_size = QtCore.QSize(int(size.width() * dpr), int(size.height() * dpr))
pixmap = QtGui.QPixmap(scaled_size)
pixmap.setDevicePixelRatio(dpr)

On my retina display, I'm seeing the canvas and window at the correct size and events seem to still report the correct x/y coordinates.

That said:

  1. I have no way to test this on Windows or Linux, where it's possible to have non-integral device pixel ratios.
  2. You probably have more experience with Qt than I do!

@timhoffm

Copy link
Copy Markdown
Member

Ok thanks for the clarification. Reviewing from the phone is not optimal as it’s harder to see all context.

@QuLogic

QuLogic commented Aug 19, 2026

Copy link
Copy Markdown
Member

The result is more complicated on Linux. If I run with QT_QPA_PLATFORM=xcb, then the resulting window is small on the 1x display and double that on the 2x display, but there is nothing wrong with the toolbar icons. If I run with QT_QPA_PLATFORM=wayland, then the resulting window is twice as big as before on the 1x display, and double that on the 2x display, but the toolbar icons are broken as in the original issue.

This PR fixes the toolbar icons in the latter case. It does not fix the inconsistency between platform libraries, which I think must have to do with the other global QApplication settings that we enable.

@QuLogic QuLogic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is possibly more to do, noted above, but this does fix the original issue.

@QuLogic QuLogic added this to the v3.11.2 milestone Aug 19, 2026
@timhoffm
timhoffm merged commit c166b33 into matplotlib:main Aug 19, 2026
39 of 41 checks passed
QuLogic pushed a commit that referenced this pull request Aug 19, 2026
QuLogic added a commit that referenced this pull request Aug 19, 2026
…221-on-v3.11.x

Backport PR #32221 on branch v3.11.x (Qt IconEngine: Use a device pixel ratio of 1 when high-DPI pixmaps are disabled)
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]: Oversized Qt5 toolbar icons on macOS Retina display since Matplotlib 3.11

3 participants