Python def on_clicked_btn(self, img): _item = QTableWidgetItem(QIcon(img), "") _item.setData(Qt.DecorationRole, QIcon(img)) self.table.setItem(self.table.currentRow(), self.table.currentColumn(), _item)
tablewidget->setCellWidget(row, column, lab);
Pythonclass TableWidgetItem(QtGui.QWidget): def __init__(self, icon, text): QtGui.QWidget.__init__(self) layout = QtGui.QHBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) label = QtGui.QLabel() label.setPixmap(QtGui.QPixmap(icon)) label.setAlignment(QtCore.Qt.AlignCenter) layout.addWidget(label)
Python def on_clicked_btn(self, img): _item = TableWidgetItem(img, " ") self.table.setCellWidget(self.table.currentRow(), self.table.currentColumn(), _item)