Thursday, January 24, 2013

Key Press Event Handler

Upon reading up on events, event filters and event handlers, I realized installing an event filter to handle additional key press events was not the best solution.  There are actually several levels at which events can be monitored and intercepted and event filters are the third level up.

The lowest level are the specific event handler functions for a widget, each of which handle a specific type of event.  The next level is the event handler for a widget that receives all types of events.  The third level is any installed event filter for the widget in backwards order of when they were installed.  There are several more levels above this that won't be detailed here.  The real purpose of event filters is for another class, like a parent widget, to monitor and intercept the events of several widgets.

Therefore, the event filter function was replaced with a key press event handler function.  This function will receive only key press events.  Instead of an if statement for checking for the Return or Enter keys, a switch statement was used since other keys will need to be handled.  Again, if the key is a Control+Return a new unmodified Return key press event is created and posted.  Unlike the event filter function, an event handler function just returns.  Being at the lowest level, there are no additional routines that will be called for the event.  Similar to the event filter, all unprocessed key press events are passed on to the base QTextEdit class key press event handler.

[commit 241fa39814]

No comments:

Post a Comment

All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)