[PyKDE] QComboBox full but box is empty

Tom Brown brown at esteem.com
Tue May 2 19:39:29 BST 2006


I have a QComboBox on my main window. I fill it with items using a model. I 
see the items in the drop down list. However, when I select an item, it does 
not show up in the box. When I call setCurrentIndex(0) the item at index 0 
does not show up in the box. What am I doing wrong?

Here is how I fill it:

  def loadModels(self):
    models = self.queryForModels()
    self.modelModel = StringsModel(models)
    self.ui.modelCB.setModel(self.modelModel)
    self.ui.modelCB.setCurrentIndex(0)

Here is my model:

class StringsModel(QAbstractListModel):
  def __init__(self, strings, parent=None):
    QAbstractListModel.__init__(self, parent)
    self.strings = strings

  def data(self, index, role):
    if not index.isValid():
      return QVariant()
    if index.row() >= len(self.strings):
      return QVariant()
    if role == Qt.DisplayRole:
      return QVariant(self.strings[index.row()])
    else:
      return QVariant()

  def rowCount(self, parent):
    return len(self.strings)


Thanks,
Tom




More information about the PyQt mailing list