
Originally Posted by
Kryzon
Try the following: just create a copy of the event with the Text property in uppercase version and pass it to the base implementation.
void MyLineEdit
::keyPressEvent( QKeyEvent* event
) {
event.accept();
QKeyEvent* modifiedEvent
= new QKeyEvent( QEvent::KeyPress, event
->key
(), event
->modifiers
(), event
->text
().
toUpper() );
}
void MyLineEdit::keyPressEvent( QKeyEvent* event )
{
event.accept();
QKeyEvent* modifiedEvent = new QKeyEvent( QEvent::KeyPress, event->key(), event->modifiers(), event->text().toUpper() );
QLineEdit::keyPressEvent( modifiedEvent );
}
To copy to clipboard, switch view to plain text mode
To quote myself as I can't edit that post, instead of creating the event in the heap like that (which is flawed in that it should lead to a leak), creating it in the stack is the right way.
QKeyEvent modifiedEvent
( QEvent::KeyPress, event
->key
(), event
->modifiers
(), event
->text
().
toUpper() );
QKeyEvent modifiedEvent( QEvent::KeyPress, event->key(), event->modifiers(), event->text().toUpper() );
QLineEdit::keyPressEvent( &modifiedEvent );
To copy to clipboard, switch view to plain text mode
The temporary event will be destroyed after the base implementation processes it.
Bookmarks