如何处理"没有属性' setCurrentText'"使用PySide Qt QComboBox

时间:2014-05-05 23:17:35

标签: python qt pyside qcombobox

当尝试使用PySide在Qt QComboBox上使用addItem时,我收到以下错误:

AttributeError:'PySide.QtGui.QComboBox'对象没有属性'setCurrentText'

如果addItem方法导致错误,如何使用ComboBox?

1 个答案:

答案 0 :(得分:0)

我不知道导致错误的原因,但我可以通过使用显式模型来使用QComboBox。

伪码:

model = QStandardItemModel(comboBox)
item1 = QStandardItem( "item1" )
item2 = QStandardItem( "item2" )
model.appendRow(item1) 
model.appendRow(item2)
comboBox.setModel(model)