Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
fix: Qt5Agg support darkmode icon by using svg#30565
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
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…Painter to avoid crash
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Not sure, but would using aQIconEngine remove the need for a manual refresh? As far as I read it, the engine could provide the right-sized image on demand (pull principle), instead of explicitly updating on a dpi-change event (push principle). |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
7c1c620
tofb0c6df
CompareUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
def_render_svg(self,svg_path,pixmap,size,dpr): | ||
"""Render SVG content to pixmap.""" | ||
QSvgRenderer=qt_compat.get_qsvg_renderer() | ||
ifQSvgRendererisNone: | ||
returnQtGui.QPixmap() |
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 find the logic not quite clean. You passpixmap
and sometimes return that pixmap with something rendered into, and sometimes you return a different pixmap. I'd rather have that we either only draw into the pixmap (and then do not need to return anything, or that we change to_create_pixmap_from_*
and not pass a pixmap in.
Uh oh!
There was an error while loading.Please reload this page.
# Get the current device pixel ratio | ||
dpr= (self.toolbar.devicePixelRatioF()or1)ifself.toolbarelse1 |
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.
Idea for further simplification:
move this into a private function_devicePixelRatio()
.
Then ...
returnself._create_pixmap_from_svg(svg_path,size,dpr) | ||
else: | ||
large_path=self.image_path.with_name(self.image_path.stem+'_large.png') | ||
path=large_pathiflarge_path.exists()elseself.image_path | ||
scaled_size=QtCore.QSize( | ||
int(size.width()*dpr), | ||
int(size.height()*dpr) | ||
) | ||
returnself._create_pixmap_from_png(path,scaled_size,dpr) |
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.
Interpretsize
as logical display size for the scope of this function and hide the calculation of the physical size fully inside the_create_pixmap_from_*
functions, usingself._devicePixelRatio()
in there.
This reduces here to
returnself._create_pixmap_from_svg(svg_path,size,dpr) | |
else: | |
large_path=self.image_path.with_name(self.image_path.stem+'_large.png') | |
path=large_pathiflarge_path.exists()elseself.image_path | |
scaled_size=QtCore.QSize( | |
int(size.width()*dpr), | |
int(size.height()*dpr) | |
) | |
returnself._create_pixmap_from_png(path,scaled_size,dpr) | |
returnself._create_pixmap_from_svg(svg_path,size) | |
else: | |
returnself._create_pixmap_from_png(self.image_path,size) |
All the type-dependent implementation details (dpi handling, using a possibly available_large
PNG image) are then hidden in the respective function.
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.
Thanks for your patient feedback and guidance. I've really learned a lot from it.💡
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.
@LangQi99 thanks as well for the patience to go through the sequence of review cycles! We try to keep them low, but in this case, the proper solution only revealed itself step-by-step. But maybe seeing the evolution of thoughts is also instructive 😃.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
PR summary
Addresses issue#27590
I noticed in a screenshot from another PR that out of the six backends displayed, only the Qt5Agg icon fails to adapt to dark mode. It remains black and blends in with the background, making it difficult to distinguish.
Old behavior

New behavior

Old behavior

New behavior

PR checklist