Renan Renan - 1 year ago 161
Python Question

QComboBox within QTableWidget returns NoneType

In one of my applications I need to have a QComboBox inside a QTableWidget.

I wrote this code:

def on_addGoal_clicked(self, checked=False):
self.ui.listOfGoals.setRowCount(self.ui.listOfGoals.rowCount() + 1)

possible_goals = QtGui.QComboBox()
possible_goals.addItems(["greater_than", "maximize", "minimize" \
, "smaller_than", "between"])

self.ui.listOfGoals.setCellWidget(self.ui.listOfGoals.rowCount() - 1,
1, possible_goals)

and it correctly adds the QComboBox.

However, when I try to retrieve this QComboBox using self.ui.listOfGoals.item(r,1), a None is returned.

I'm still new to PyQt so I might have missed something here. Any suggestions?

Answer Source

Use the cellWidget method to retrieve a widget that was set with setCellWidget:

possible_goals = self.ui.listOfGoals.cellWidget(r, 1)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download