from PySide2.QtWidgets import QApplication, QPushButton from PySide2.QtGui import QIcon app = QApplication([]) button = QPushButton() icon = QIcon('icon.png') button.setIcon(icon) button.show() app.exec_()
from PySide2.QtWidgets import QApplication, QSystemTrayIcon from PySide2.QtGui import QIcon, QPixmap app = QApplication([]) icon = QIcon(QPixmap('icon.png')) tray = QSystemTrayIcon(icon, app) tray.show() app.exec_()
from PySide2.QtWidgets import QApplication, QLabel from PySide2.QtGui import QIcon, QPixmap app = QApplication([]) pixmap = QPixmap(':/Icons/icon.png') icon = QIcon(pixmap) label = QLabel() label.setPixmap(pixmap) label.show() app.exec_()These examples demonstrate how PySide2.QtGui QIcon can be used to manage icons in a wide range of scenarios, from setting the icon of a button in a graphical user interface, to displaying an icon in a system tray, or a resource file. The PySide2.QtGui module is part of the PySide2 package, which is a Python binding of the Qt framework by The Qt Company.