[PyKDE] Listbox returns dictionary key?
Peter Clark
peter-clark at bethel.edu
Thu Aug 7 05:34:01 BST 2003
Let's say I want to populate a listbox with a list of dictionary keys:
d = {'cat':'Fluffy', 'dog':'Wolfie'}
k = d.keys()
k.sort()
<Create listbox, and populate it with the items in k>
At this point, I've got a listbox with two items:
cat
dog
Now,
self.connect(self.listBox, SIGNAL("selected(int)"), self.printWhatWeSelected)
returns '0' if I select cat, '1' for 'dog', etc. To get the dictionary value
for that selection, I could do
d[k[int]]
but this requires that I pass both d and k to the respective function, or make
them both global. Is it possible for the listbox to report the text of what
was selected, so that I could just use the text as the key?
Also, what magic is required for changing the signal to "clicked()" rather
than "selected()"? I tried both clicked() and clicked(int) but got an error
saying:
QObject::connect: No such signal QListBox::clicked(int)
QObject::connect: (sender name: 'listBox')
QObject::connect: (receiver name: 'unnamed')
Thanks again for letting me pick your brains,
:Peter
--
Oh what a tangled web they weave who try a new word to conceive!
More information about the PyQt
mailing list