【问题标题】:QComboBox within QTableWidget returns NoneTypeQTableWidget 中的 QComboBox 返回 NoneType
【发布时间】:2012-02-16 23:53:45
【问题描述】:

在我的一个应用程序中,我需要在 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 的新手,所以我可能在这里遗漏了一些东西。有什么建议吗?

【问题讨论】:

    标签: python qt pyqt qtablewidget qcombobox


    【解决方案1】:

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

    possible_goals = self.ui.listOfGoals.cellWidget(r, 1)
    

    【讨论】:

      猜你喜欢
      • 2017-02-04
      • 1970-01-01
      • 2010-11-22
      • 1970-01-01
      • 2018-02-15
      • 1970-01-01
      • 2020-06-26
      • 2017-02-27
      • 1970-01-01
      相关资源
      最近更新 更多