Disable 'Return' key in a QPlainTextEdit
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 avoi开发者_如何学Cd changing the command line code.
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
精彩评论