[PyQt] A quick question about Return in a text edit

Detlev Offenbach detlev at die-offenbachs.de
Wed Dec 5 17:27:26 GMT 2012


Hi,

you are right. keyPressEvent() should do the job.

Detlev

On Monday 03 December 2012, 17:56:12 Evan Driscoll wrote:
> I want to make a UI that carries out an action when the user presses
> return (think like in Pidgin), and I have a couple questions about how
> to do this. I've dabbled a very small amount but I'm basically a (Py)Qt
> newb.
> 
> From what I can tell, I want to use a QPlainTextEdit. I don't think a
> QLineEdit will work because I will sometimes need multiple lines, but
> they'll arise in ways other than the user pressing enter. (Again, think
> about Pidgin: enter sends a message, shift-enter adds a newline.)
> 
> Looking at the signals that are available, I don't see one that says
> what key has been pressed. I might be able connect a slot to
> textChanged() then do something like figure out what the cursor is and
> then look at the preceding character or something like that, but it
> seems much better to create a subclass of QPlainTextEdit and override
> the keyPressEvent() (or maybe keyReleaseEvent()?) function.
> 
> Does this all seem reasonable, or am I missing a better approach?
> 
> Evan
-- 
Detlev Offenbach
detlev at die-offenbachs.de
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20121205/6689be36/attachment.html>


More information about the PyQt mailing list