from PySide2.QtGui import QIcon # Create a QIcon object icon = QIcon() # Add a file icon icon.addFile('path/to/file.png') # Use the icon in a PyQt application button = QPushButton() button.setIcon(icon)
from PySide2.QtGui import QIcon # Create a QIcon object icon = QIcon() # Add icons of different sizes icon.addFile('path/to/file16x16.png', QSize(16, 16)) icon.addFile('path/to/file32x32.png', QSize(32, 32)) icon.addFile('path/to/file64x64.png', QSize(64, 64)) # Use the icon in a PyQt application button = QPushButton() button.setIcon(icon)Package Library: The PySide2.QtGui QIcon addFile() method is part of the PySide2 library.