1

在我的一个应用程序中,我需要在 QTableWidget 中有一个 QComboBox。

我写了这段代码:

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)

它正确地添加了 QComboBox。

但是,当我尝试使用 self.ui.listOfGoals.item(r,1) 检索此 QComboBox 时,会返回 None。

我还是 PyQt 的新手,所以我可能在这里错过了一些东西。有什么建议么?

4

1 回答 1

1

使用cellWidget方法来检索使用 设置的小部件setCellWidget

possible_goals = self.ui.listOfGoals.cellWidget(r, 1)
于 2012-02-17T03:23:31.390 回答