In my code there is a bunch of calls which try to create QIcons
from
QStyle
standard pixmaps, like:
QIcon groupIcon;
groupIcon.addPixmap( style()->standardPixmap( QStyle::SP_DirClosedIcon ),
QIcon::Normal, QIcon::Off );
groupIcon.addPixmap( style()->standardPixmap( QStyle::SP_DirOpenIcon ),
QIcon::Normal, QIcon::On );
While this works correctly, in that using the icon for a model's
Qt::DecorationRole
shows either an open or closed icon based on the item's
expanded state, it has two issues:
- It's not hi-dpi friendly, and the icons are tiny
QStyle::standardPixmap
is marked as obsolete, withQStyle::standardIcon
being described as the preferred approach.
I'm unsure how to translate the above code to QStyle::standardIcon
though.
QIcon groupIcon( style()->standardIcon( QStyle::SP_DirClosedIcon ) );
works nicely for closed items, and looks great on hidpi. But I can't see how I would add the SP_DirOpenIcon
state. There's no equivalent method like "QIcon::addIcon
" like there is QIcon::addPixmap
.
What's the correct approach to take here, which is hi-dpi friendly and future proof?