Solved Toolbar icons resolution in Qt application and dark/light modes
-
Hello,
I cannot seem to find a good guide on toolbar icons best practices. Can you please help me with these questions:- Is PNG the best format for icons?
- I see 16x16, 32x32, 64x64, 256x256, etc. Looks like I need to have all different sizes available. Does Qt do auto-sizing of icons? Wondering if I can have one large size and have Qt automatically size the icons?
- Do we need to separate light mode and dark mode icons? Does Qt Creator use just one set of icons and either invert OR color the background? I couldn't figure out by looking at the source code.
Thanks.
-
Hi
1: its a good format in both speed and size.
However, SVG can also be used and they can be scaled good.
However, dont expect a perfect result for say 16x16 as there is a reason that people
hand resize the icons and fix up some of them to look better in very small.
2: That is the normal way for max fidelity as then no scaling and you know how all will look.
QIcon can scale icons.QPixmap pixmap = icon.pixmap(QSize(22, 22), // ask for a 22x22 icon isEnabled() ? QIcon::Normal : QIcon::Disabled, isChecked() ? QIcon::On : QIcon::Off);
so yes you can have one large one and it will try its best for smaller.
Do note, QIcon is no so happy to scale up.3: Nope. Icons wont follow dark/light at all. you need 2 sets or
add some code to Darkify them before use.
Other option is to use tool like ImageMagick
to automatically do something to the light icon set to make it dark. -
@mrjj Thank you so much for the answers.