Skip to content

silx.gui.icons: Improved silx icons to support dark color theme#4593

Draft
t20100 wants to merge 1 commit into
mainfrom
icons-dark-mode
Draft

silx.gui.icons: Improved silx icons to support dark color theme#4593
t20100 wants to merge 1 commit into
mainfrom
icons-dark-mode

Conversation

@t20100
Copy link
Copy Markdown
Member

@t20100 t20100 commented May 6, 2026

PR summary

This PR adds a QIconEngine to hook into QIcon rendering and "patch" the svg when the application is in dark mode.
This adds a bit of complexity to the icon module but it is fully transparent from a user point of view: Icons automatically adapts to color scheme changes.

There is still some thing to be done:

  • how to handle icons that explicitly want to keep a black color
  • remove white background in some icons
  • use slightly brighter green&blue, but it already gives this:

lightimage

related to #4486

AI Disclosure

  • AI tool(s) copilot used to bootstrap SvgIconEngine + tabby/qwen & copilot for autocompletion

@t20100 t20100 added this to the Next release milestone May 6, 2026
Comment thread src/silx/gui/icons.py
Comment on lines +421 to +422
qfile = getQFile(name)
icon = qt.QIcon(qfile.fileName())
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Kept previous implementation for other application using silx icon mechanism but in silx we can consider completely remove .png icons.

Comment thread src/silx/gui/icons.py
Comment on lines +108 to +110
svgpath = re.sub(
b'fill="(#000000|#000)"', f'fill="{foreground}"'.encode(), svgpath
)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

svg default fill is black and this can be overridden in with fill declared in the <svg> tag.
To complete this PR, the idea is to patch existing icons to remove unnecessary fill="#000" so this substitution is not needed. This would allow to explicitly set a fill color to black even in dark mode.

Comment thread src/silx/gui/icons.py
Comment on lines +111 to +113
svgpath = re.sub(
b'stroke="(#000000|#000)"', f'stroke="{foreground}"'.encode(), svgpath
)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

svg default stroke is "none" so overriding the default in <svg> does not work as for fill....

Comment thread src/silx/gui/icons.py
Comment on lines +124 to +127
if isDark != self._isDarkColorScheme:
self._renderer.load(self._darkSvgPath if isDark else self._lightSvgPath)
self._isDarkColorScheme = isDark

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reload icon only when needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant