I have created a subclass of QComboBox where I want to catch keys from 'a' to 'z' and manually force them to capital letters 'A'-'Z'. It has to be done real-time like caps lock was pressed.
I'm trying the following approach w/o success:
void CommandBox
::keyPressEvent(QKeyEvent *e
) { if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
emit enterPressed(currentText());
} else if (e->key() >= Qt::Key_A && e->key() <= Qt::Key_Z) {
if (capital) e->setModifiers(Qt::ShiftModifier);
}
qDebug() << e->key() << e->modifiers();
}
void CommandBox::keyPressEvent(QKeyEvent *e) {
if (e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter) {
emit enterPressed(currentText());
} else if (e->key() >= Qt::Key_A && e->key() <= Qt::Key_Z) {
if (capital) e->setModifiers(Qt::ShiftModifier);
}
qDebug() << e->key() << e->modifiers();
QComboBox::keyPressEvent(e);
}
To copy to clipboard, switch view to plain text mode
The modifier is set, I can see it in the printout of qDebug(), but the character is still lower case in the field.
Any guess?
Thanks!
Bookmarks