[PyQt] problem with pyqt 4.6

Phil Thompson phil at riverbankcomputing.com
Fri Oct 16 15:54:45 BST 2009


On Fri, 16 Oct 2009 16:27:00 +0200, Linos <info at linos.es> wrote:
> i dont know if this is a bug or a change in behaviour but keyPressEvent
> dont 
> catch the keyboard events in my QWidget or QDialog subclasses. In the
> example 
> added with PyQt 4.4 you can press any key and get his int code printed
but
> with 
> last snapshot it never prints anything.
> 
> ----- CODE
> 
> # -*- coding: utf-8 -*-
> import sys
> from PyQt4.QtCore import *
> from PyQt4.QtGui import *
> 
> class TestWidget(QWidget):
>      def __init__(self, parent):
>          super(TestWidget, self).__init__()
> 
>          self.button = QPushButton("test")
> 
>          layout = QVBoxLayout()
>          layout.addWidget(self.button)
>          self.setLayout(layout)
> 
>      def keyPressEvent(self, event):
>          print event.key()
> 
> 
> def main():
>      app = QApplication(sys.argv)
> 
>      widget = TestWidget(None)
>      widget.show()
>      return app.exec_()
> 
> if __name__ == "__main__":
>      main()

Works fine for me.

Phil


More information about the PyQt mailing list