Question

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?

Was it helpful?

Solution

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

possible_goals = self.ui.listOfGoals.cellWidget(r, 1)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top