Re: [PyQt] A quick question about Return in a text edit (Evan Driscoll)

2012-12-05 Thread Evan Driscoll

On 12/04/2012 09:38 AM, David Cortesi wrote:

This type of question is better addressed to the Qt fora,
see qt-project.org/forums. That said...

You definitely can monitor all keystrokes using keyPressEvent.
You will likely find other reasons for doing so besides shift-enter,
for example you might trap ^f to implement find.

A whole lot of stuff comes through keyPressEvent, write a
simple one first that just prints the event's members out to the
console to get an idea. You will get very familiar with the key enum
in the Qt namespace.

Also for entering "newline"? In Q[Plain]TextEdit, you want to insert
the Unicode para separator, \u2029. Not \n.

Also, get Summerhill's book if you don't have it.


Thank you (and Detlev) for your responses!

EVan







On Tue, Dec 4, 2012 at 4:00 AM,   wrote:


 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.

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


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

2012-12-05 Thread Detlev Offenbach
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
det...@die-offenbachs.de___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Re: [PyQt] A quick question about Return in a text edit (Evan Driscoll)

2012-12-04 Thread David Cortesi
This type of question is better addressed to the Qt fora,
see qt-project.org/forums. That said...

You definitely can monitor all keystrokes using keyPressEvent.
You will likely find other reasons for doing so besides shift-enter,
for example you might trap ^f to implement find.

A whole lot of stuff comes through keyPressEvent, write a
simple one first that just prints the event's members out to the
console to get an idea. You will get very familiar with the key enum
in the Qt namespace.

Also for entering "newline"? In Q[Plain]TextEdit, you want to insert
the Unicode para separator, \u2029. Not \n.

Also, get Summerhill's book if you don't have it.



On Tue, Dec 4, 2012 at 4:00 AM,   wrote:

> 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.
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


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

2012-12-03 Thread Evan Driscoll
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




signature.asc
Description: OpenPGP digital signature
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt