def mk_icons( style: QStyle, size: QSize, ) -> dict[str, QIcon]: '''This helper is indempotent. ''' global _icons, _icon_names if _icons: return _icons _icons[None] = QIcon() # the "null" icon # load account selection using current style for name, icon_name in _icon_names.items(): stdpixmap = getattr(QStyle, icon_name) stdicon = style.standardIcon(stdpixmap) pixmap = stdicon.pixmap(size) # fill hack from SO to change icon color: # https://stackoverflow.com/a/38369468 out_pixmap = QPixmap(size) out_pixmap.fill(QColor(hcolor('default_spotlight'))) out_pixmap.setMask(pixmap.createHeuristicMask()) # TODO: not idea why this doesn't work / looks like # trash. Sure would be nice to just generate our own # pixmaps on the fly.. # p = QPainter(out_pixmap) # p.setOpacity(1) # p.setBrush(QColor(hcolor('papas_special'))) # p.setPen(QColor(hcolor('default_lightest'))) # path = mk_marker_path(style='|<') # p.scale(6, 6) # # p.translate(0, 0) # p.drawPath(path) # p.save() # p.end() # del p # icon = QIcon(out_pixmap) icon = QIcon() icon.addPixmap(out_pixmap) _icons[name] = icon return _icons
from PyQt5.QtWidgets import QGridLayout, QPushButton, QStyle layout = QGridLayout() iconIndex = 0 for row in range(7): for col in range(10): standardIcon = iconIndex layout.addWidget(QPushButton(QStyle.standardIcon(standardIcon)))