[PyKDE] Zaurus buttons in a PyQt QListBox

Dave Reed dreed at capital.edu
Tue May 14 12:32:00 BST 2002


The Zaurus buttons (round select button and 4 arrows around it) don't
generate PyQt signals (at least in a QListBox). They do affect the
display (i.e., pressing the round select button causes a list box item
to be highlighted, but no event is generated). Thanks to Phil Thompsons's
suggestions in a private email, I got it working by providing my own
keyPressEvent function. This seems like an ugly hack, especially
having to call setSelected. Does anyone have a more elegant solution?

-----------------------------------------------------------------

class QListBoxZaurusKeyEvent(QListBox):
    def __init__(self, parent, name, flags=0):
        QListBox.__init__(self, parent, name, flags)
        self.app = parent
        
    def keyPressEvent(self, key_event):
        index = self.currentItem()
        key = key_event.key()

        if key == 32: # Zaurus round button
            self.emit(SIGNAL('clicked(QListBoxItem*)'), (self.item(index),))
            if self.isSelected(index):
                self.setSelected(index, 0)
            else:
                self.setSelected(index, 1)

        elif key == 4117: # Zaurus down arrow
            self.setCurrentItem(index + 1)

        elif key == 4115: # Zaurus up arrow
            self.setCurrentItem(index - 1)

        elif key == 4114: # Zaurus left arrow
            pass

        elif key == 4116: # Zaurus right arrow
            pass

        elif key == 4100: # Zaurus Ok button
            self.emit(SIGNAL('selected(QListBoxItem*)'), (self.item(index),))

-----------------------------------------------------------------

Thanks,
Dave




More information about the PyQt mailing list