Skip to content

Instantly share code, notes, and snippets.

@centaurialpha
Last active November 2, 2025 22:07
Show Gist options
  • Save centaurialpha/cfd7de48cb3e4d8e0d17f475b7ad3118 to your computer and use it in GitHub Desktop.
Save centaurialpha/cfd7de48cb3e4d8e0d17f475b7ad3118 to your computer and use it in GitHub Desktop.
Show all standard Qt icons
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtWidgets import QGridLayout
from PyQt5.QtWidgets import QStyle
COL_SIZE = 4
class Widget(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle('Standard Icons')
layout = QGridLayout(self)
count = 0
for attr in dir(QStyle):
if attr.startswith('SP_'):
icon_attr = getattr(QStyle, attr)
btn = QPushButton(attr)
btn.setIcon(self.style().standardIcon(icon_attr))
layout.addWidget(btn, count // COL_SIZE, count % COL_SIZE)
count += 1
if __name__ == '__main__':
app = QApplication([])
w = Widget()
w.show()
app.exec_()
@zorn-v
Copy link

zorn-v commented Jan 19, 2025

Adapted for QT6 plus bonus - copy icon name on click

#!/usr/bin/env python3

from PyQt6.QtWidgets import QApplication, QWidget, QPushButton, QGridLayout, QStyle
from PyQt6.QtGui import QGuiApplication

COL_SIZE = 4

class Widget(QWidget):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setWindowTitle('Standard Icons')
        layout = QGridLayout(self)
        count = 0
        clipboard = QGuiApplication.clipboard()
        for attr in dir(QStyle.StandardPixmap):
            if attr.startswith('SP_'):
                icon_attr = getattr(QStyle.StandardPixmap, attr)
                btn = QPushButton(attr)
                btn.setIcon(self.style().standardIcon(icon_attr))
                def clip_copy_fn(text):
                    def clip_copy():
                        clipboard.setText(text)
                    return clip_copy
                btn.clicked.connect(clip_copy_fn(attr))
                layout.addWidget(btn, count // COL_SIZE, count % COL_SIZE)
                count += 1


if __name__ == '__main__':
    app = QApplication([])
    w = Widget()
    w.show()
    app.exec()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment