[PyKDE] Getting control over the Tab key

Fredrik Juhlin laz at strakt.com
Thu Oct 24 09:26:00 BST 2002


On Wed, 2002-10-23 at 20:28, Konrad Hinsen wrote:
> > They may be filtered out by the widget that has focus, it's hard to
> 
> At least they never appear in keyPressEvent(), neither for the main
> widget nor for the widget in focus.
Since you haven't posted any code it's hard to tell what you're doing
wrong. Are you sure that your widget accepts keyboard focus? Unless you
are subclassing a widget that does, you'll have to call
QWidget::SetFocusPolicy() with the appropriate argument
(Qt::StrongFocus, for instance).

Below is a piece of code that works as expected. I don't call
QWidget::SetFocusPolicy() since QLineEdit does that for me.

import qt
import sys

class MyLineEdit(qt.QLineEdit):
    def keyPressEvent(self, event):
        qt.QLineEdit.keyPressEvent(self, event)
        if event.key() == qt.Qt.Key_Tab:
            print "Tab pressed"
    
app = qt.QApplication(sys.argv)
en = MyLineEdit(None)
app.setMainWidget(en)
en.show()
app.exec_loop()

//Fredrik




More information about the PyQt mailing list