문제

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?

도움이 되었습니까?

해결책

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

possible_goals = self.ui.listOfGoals.cellWidget(r, 1)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top