Le 08/09/10 11:06, [email protected] a écrit :
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    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

  
Hi,

Why ' self.plainTextEdit.keyPressEvent(event) ' is into the def ?

Like this, that's works :

#!/usr/bin/env python
# -*- coding: utf-8 -*-


from PyQt4 import QtCore, QtGui

class MainGui(object):
    def setupUi(self, MainWindow):
        MainWindow.resize(218, 379)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.layout = QtGui.QVBoxLayout(self.centralwidget)
        self.p_text = QtGui.QPlainTextEdit(self.centralwidget)
        self.layout.addWidget(self.p_text)
        MainWindow.setCentralWidget(self.centralwidget)

        self.p_text.keyPressEvent = self.keyPressEvent

    def keyPressEvent(self, e):
        print "event", e
        if e.key()  == QtCore.Qt.Key_Return :
            print  ' return'
        elif e.key() == QtCore.Qt.Key_Enter :  
            print ' enter'

if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    MainWindow = QtGui.QMainWindow()
    ui = MainGui()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())


--
Vincent V.V.
Oqapy
_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to