from PyQt5.QtWidgets import QAction, QApplication from PyQt5.QtGui import QIcon import sys app = QApplication(sys.argv) action = QAction('Copy', None) action.setIcon(QIcon('copy.png')) app.exec_()
from PyQt5.QtWidgets import QAction, QApplication from PyQt5.QtGui import QPixmap import sys app = QApplication(sys.argv) pixmap = QPixmap('copy.png') action = QAction('Copy', None) action.setIcon(QIcon(pixmap)) app.exec_()In this example, we first create an instance of QPixmap named 'pixmap' from the file 'copy.png'. Then we set the icon for QAction using QIcon with the existing pixmap instance. Package library: PyQt5.QtWidgets