Skip to content

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

Open
iccir wants to merge 1 commit into
matplotlib:mainfrom
iccir:fix-qt5-toolbar-icons
Open

Qt IconEngine: Use a device pixel ratio of 1 when high-DPI pixmaps are disabled#32221
iccir wants to merge 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!

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

2 participants