[PyQt] Key return

Matt Smith melkor at orangepalantir.org
Sun Nov 2 17:46:44 GMT 2008


>Date: Sat,  1 Nov 2008 18:46:29 +0100
> From: "lucaberto\@libero\.it" <lucaberto at libero.it>
> Subject: [PyQt] Key return
> To: "pyqt" <pyqt at riverbankcomputing.com>
> Message-ID: <K9O1DH$AB8CE19B38A8774437A43FEF37AD48C7 at libero.it>
> Content-Type: text/plain; charset=iso-8859-1
> 
> Hello
> i need that when i press the Return key, one button intercept the pression of it and process the event
> Can you explain me how i can do it
> 
> Regards
> 
> Luca
> 
Its a little unclear what you are asking. If you do not want the original widget to process the event then you would need to redifine the keyPressEvent() to emit a signal with the event as an argument.
Then you connect your button widget to that event.  Line Edits will already send the event, and I"m not sure if you can sent a QEvent as a signal.  I don't know what it's appropriate c signature is offhand.

def keyPressEvent(self,event):
    if event.key()==QtCore.Qt.Key_Return:
        self.emit(QtCore.SIGNAL("returnPressed( QEvent )"),event)
    else:
        event.accept()





More information about the PyQt mailing list