0

Basically i have combo boxes in many rows inside QTableWidget and i want to retrieve all the cells in row in which the combo-box value currentTextChanged. i have combobox link to the QTableWidget like this,

enter image description here

and i connect the updateTableWidget Listener in this Qcombobox like this,

# objTableWidget of QTableWidget
cbxResult = QtWidgets.QComboBox()
cbxResult.addItems(["Matched", "Not Matched"])
objTableWidget.setCellWidget(rowCount, colCount, cbxResult)
cbxResult.currentTextChanged.connect(lambda: self.updateTableWidget(rowCount, colCount, objTableWidget=objTableWidget))

and the self.updateTableWidget function is,

def updateTableWidget(row:int, col:int, objTableWidget:object):
    
    print(objTableWidget.rowCount())
    print(objTableWidget.objectName())
    objCellWidget = objTableWidget.item(row, col)
    strCellVal = objCellWidget.text()

the objCellWidget = objTableWidget.item(row, col) return a NoneType and strCellVal = objCellWidget.text() NoneType has no attribute 'text()'.

the objCellWidget = objTableWidget.item(row, col) is working fine with default TableWidget lineEdit but doesn't work with custom Widget like i use Combobox Widget in QTableWidget.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • 1
    use `cbxResult.currentTextChanged.connect(lambda *args, row=rowCount, col=colCount, table=objTableWidget: self.updateTableWidget(row, col, objTableWidget=table)) ` – eyllanesc Mar 30 '21 at 19:28
  • add change to `objCellWidget = objTableWidget.cellWidget(row, col)`. You have not added a QTableWidgetItem to the cell with the setItem() method but a QWidget with the setCellWidget() method so you must use the cellWidget() method to get the widget. – eyllanesc Mar 30 '21 at 19:28
  • @eyllanesc Thanks for quick reply,, your first suggestion works perfectly. – Ahsan Akram Mar 30 '21 at 20:10

0 Answers0