I have a simple application with just one QPlainTextEdit, basically the same as Qt's example here:
http://qt-project.org/doc/qt-5.1/qtwidgets/mainwindows-application.html
When I press Ctrl+Z, it calls undo. When I press Ctrl+A, it selects all text. This is ok.
But when I press Ctrl+E or Ctrl+R, which are not defined in the menu, the characters "e" and "r" will appear in the QSimpleTextEdit.
How do I prevent this? How to "filter" keypresses which have been defined as menu shortcuts and keep them working, and "prevent" those keypresses not defined as menu shortcuts from appearing in the edit?
Calling preventDefault() during any stage of event flow cancels the event, meaning that any default action normally taken by the implementation as a result of the event will not occur. You can use Event. cancelable to check if the event is cancelable. Calling preventDefault() for a non-cancelable event has no effect.
This low-level event is generated by a component object (such as a text field) when a key is pressed, released, or typed. The event is passed to every KeyListener or KeyAdapter object which registered to receive such events using the component's addKeyListener method.
How do I turn off keypress events? Alternatively, you could attach another event handler to the input field, and in this handler stop the propagation of the event: jQuery('#input-field-id'). bind('keypress', function(e) { e. stopPropagation(); });
The preventDefault() method cancels the event if it is cancelable, meaning that the default action that belongs to the event will not occur. For example, this can be useful when: Clicking on a "Submit" button, prevent it from submitting a form. Clicking on a link, prevent the link from following the URL.
There are 2 options:
1) Create a subclass and reimplement keyPressEvent()
2) Create an eventFilter and use installEventFilter()
(see http://qt-project.org/doc/qt-5.0/qtcore/qobject.html#installEventFilter)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With