<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
Le 08/09/10 11:06, <a class="moz-txt-link-abbreviated" href="mailto:lucaberto@libero.it">lucaberto@libero.it</a> a écrit :
<blockquote
cite="mid:19600964.4009571283936819008.JavaMail.root@wmail50"
type="cite">
<pre wrap="">hello i need to intercept the return and the enter key in a plaintextedit and i
have write this
def keyPressEvent(self, event):
self.plainTextEdit.keyPressEvent(event)
if event.key() == QtCore.Qt.Key_Return :
print ' return'
elif event.key() == QtCore.Qt.Key_Enter :
print ' enter'
but the def keyPressEvent is called only if i press for ex blocnum and not
when i push normal letter or return or enter.
Can you explain me how to do it
Thanks
Luca
_______________________________________________
PyQt mailing list <a class="moz-txt-link-abbreviated" href="mailto:PyQt@riverbankcomputing.com">PyQt@riverbankcomputing.com</a>
<a class="moz-txt-link-freetext" href="http://www.riverbankcomputing.com/mailman/listinfo/pyqt">http://www.riverbankcomputing.com/mailman/listinfo/pyqt</a>
</pre>
</blockquote>
Hi,<br>
<br>
Why ' self.plainTextEdit.keyPressEvent(event)
' is into the def ?<br>
<br>
Like this, that's works :<br>
<br>
#!/usr/bin/env python<br>
# -*- coding: utf-8 -*-<br>
<br>
<br>
from PyQt4 import QtCore, QtGui<br>
<br>
class MainGui(object):<br>
def setupUi(self, MainWindow):<br>
MainWindow.resize(218, 379)<br>
self.centralwidget = QtGui.QWidget(MainWindow)<br>
self.layout = QtGui.QVBoxLayout(self.centralwidget)<br>
self.p_text = QtGui.QPlainTextEdit(self.centralwidget)<br>
self.layout.addWidget(self.p_text)<br>
MainWindow.setCentralWidget(self.centralwidget)<br>
<br>
self.p_text.keyPressEvent = self.keyPressEvent<br>
<br>
def keyPressEvent(self, e):<br>
print "event", e<br>
if e.key() == QtCore.Qt.Key_Return :<br>
print ' return'<br>
elif e.key() == QtCore.Qt.Key_Enter : <br>
print ' enter'<br>
<br>
if __name__ == "__main__":<br>
import sys<br>
app = QtGui.QApplication(sys.argv)<br>
MainWindow = QtGui.QMainWindow()<br>
ui = MainGui()<br>
ui.setupUi(MainWindow)<br>
MainWindow.show()<br>
sys.exit(app.exec_())<br>
<br>
<br>
<div class="moz-signature">-- <br>
Vincent V.V.<br>
<a href="https://launchpad.net/oqapy">Oqapy</a></div>
</body>
</html>