[PyKDE] QComboBox question...

Yannick Gingras yannick.gingras at savoirfairelinux.com
Wed Nov 5 17:41:00 GMT 2003


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On November 5, 2003 06:57 am, GuineaPig wrote:

> I can't find a clear answer on this, maybe I'm overlooking something ?

You can't assign arbitrary indexes to items in the QComboBox, the
index parameter to insertItem() is where you want to insert your new
item in an already populated QComboBox.  You can easily customize the
indexes by storing a list of pks of what you put in your QComboBox:

  def initCombo(self, records):
      self.comboItems = []
      self.combo.clear()
      for record in records:
          self.combo.insertItem(record["label"])
          self.comboItems.append(record["pk"])

  def getSelectedPK(self):
      """returns record["pk"]"""
      return self.comboItems[self.combo.currentItem()]

assuming that your record set look like this :

  records = [ {"pk":     42, 
 	       "label": "Mjolnir"}, 
              {"pk":     43, 
 	       "label": "Grayswandir"}, 
              {"pk":     44, 
 	       "label": "Excalibur"} ]

- -- 
Yannick Gingras
Byte Gardener, Savoir-faire Linux inc.
http://www.savoirfairelinux.com/


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/qSexrhy5Fqn/MRARAtjZAJ9OTIOffEjHqJ5Qeub3vZqcCWxGcwCfeZMB
ct37OC0BSwNLJoXBJOFtZnE=
=+uZQ
-----END PGP SIGNATURE-----




More information about the PyQt mailing list