Skip to content
hannes edited this page Feb 15, 2023 · 4 revisions

Icon

Default icons

All default Qt resources can be seen with this code. Note default resources can vary between apps. example path: :/qt-project.org/styles/commonstyle/images/up-32.png you can use this string in the config

!print all qt resources-1676464679534.jpeg

from PySide2.QtCore import QDirIterator

it = QDirIterator(":", QDirIterator.Subdirectories)

all_resource_paths = []
while it.hasNext():
    value = it.next()
    if value.endswith(".png"):
        all_resource_paths.append(value)



import sys

from PySide2.QtWidgets import QApplication, QGridLayout, QPushButton, QStyle, QWidget
import PySide2.QtGui

class Window(QWidget):
    def __init__(self):
        super(Window, self).__init__()

       # icons = sorted([attr for attr in dir(QStyle) if attr.startswith("SP_")])
        layout = QGridLayout()

        for n, name in enumerate(all_resource_paths):
            btn = QPushButton()
            btn.setToolTip(name)
            pixmap = PySide2.QtGui.QPixmap(name)
            icon = PySide2.QtGui.QIcon(pixmap)
            btn.setIcon(icon)
            layout.addWidget(btn, n / 25, n % 25)

        self.setLayout(layout)

w = Window()
w.show()

Custom icons

TODO provide example

  1. add icon to Qresources
  2. use the path-string in the icon attribute see https://www.pythonguis.com/tutorials/qresource-system/

separator

How a separator is represented depends on the widget it is inserted into. Under most circumstances the text, submenu, and icon will be ignored for separator actions. source