Last active
November 2, 2025 22:07
-
-
Save centaurialpha/cfd7de48cb3e4d8e0d17f475b7ad3118 to your computer and use it in GitHub Desktop.
Show all standard Qt icons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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_() |
Author
centaurialpha
commented
May 20, 2020
| Linux | Windows |
|---|---|
![]() |
|
| Click image to enlarge | Click image to enlarge |
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
