QEvent::KeyPress for Enter and Return, Detection Qt::Modifiers on Enter doesn't work
Hello,
i have a eventFilter where i catch a presses Key like this:
Code:
if ( event
->type
() == QEvent::KeyPress) {
QKeyEvent *keyEvent
= static_cast<QKeyEvent
*>
(event
);
switch ( keyEvent->key() )
{
case Qt::Key_Enter:
qDebug() << "Enter";
case Qt::Key_Return:
{
qDebug() << "Return";
if( keyEvent->modifiers()==Qt::NoModifier )
{
qDebug() << "NoModifier";
}
if( keyEvent->modifiers()==Qt::ShiftModifier )
{
qDebug() << "ShiftModifier";
}
break;
}
case Qt::Key_Escape:
qDebug() << "Escape"
default:
break;
}
}
when I press "Return", everything is OK i get as output
Return
NoModifier or ShiftModifier
but when I press "Enter" the detection of the modifiers doesn't work. The output is always
Enter
Return
(no output of "NoModifier" or "ShiftModifier")
What I'm doing wrong?
Thx
Stefan
Re: QEvent::KeyPress for Enter and Return, Detection Qt::Modifiers on Enter doesn't w
Have you tried changing the check for the shift modifier to that it checks if the shift modifier is present?
Currently you check if it is the only modifier.
In general: you have if statements that that do not handle all cases. If they do not trigger, their conditions are not met.
You can easily find out why by looking at the values using in these conditions. That's called debugging.
Cheers,
_