from PyQt5.QtWidgets import QApplication, QTableWidget, QTableWidgetItem from PyQt5.QtGui import QIcon app = QApplication([]) table = QTableWidget(3, 3) icon = QIcon("my_icon.png") cell = QTableWidgetItem() cell.setIcon(icon) table.setItem(0, 0, cell) table.show() app.exec()
from PyQt5.QtWidgets import QApplication, QTableWidget, QTableWidgetItem from PyQt5.QtGui import QIcon app = QApplication([]) table = QTableWidget(3, 3) icon = QIcon("my_icon.png") for row in range(3): for column in range(3): cell = QTableWidgetItem() if column == 0: cell.setIcon(icon) table.setItem(row, column, cell) table.show() app.exec()In this example, we add an icon to the first column of each row in the table widget. We use a nested loop to iterate through each cell and check if the current column is the first column. If it is, we set the icon to the cell using the `setIcon` method. The package library used here is PyQt5.QtWidgets.