QTableWidget 中的 QComboBox 返回 NoneType
在我的一个应用程序中,我需要在 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 还很陌生,所以我可能在这里错过了一些东西。有什么建议吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 cellWidget 方法检索已设置的小部件使用
setCellWidget
:Use the cellWidget method to retrieve a widget that was set with
setCellWidget
: