tags:

views:

61

answers:

1

Is there any way I can prevent the user from hitting the return key when entering text in a QPlainTextEdit widget? That is, even though I want to give the viewing space of multiple lines, I want that the if the user hits enter, a new line should not begin.

The reason for doing this is that I am adding a GUI layer on top of an existing command-line and if the user enters data using the return key, it might complicate stuff and I had really avoid changing the command line code.

+1  A: 

Handle the key press event and filter out any return keys.
There isn't IIRC a 'allowed chars' validator for a qtextedit.

Although you can use QValidator with a QLineEdit.
See this example

ps. If you also have to deal with pasting in text with a CR, then you need to deal with the textchanged signal as well

Martin Beckett
@Martin: Right thanks for the `textchanged` thought, I had not taken into account the pasting text problem.
Thomas M