1 year ago
#381251
Artem.rtv
Double triggering QEvent::KeyPress and QEvent::KeyRelease
I have a problem: I'm trying to catch a keystroke. I use eventFilter:
bool Inf_int_qt::eventFilter(QObject *obj, QEvent *event)
{
// ::SoundKeys(event);
this->SoundKeys(event);
return true;
}
Next I do the following checks:
void Inf_int_qt::SoundKeys(QEvent* event)
{
if(event->type() == QEvent::KeyPress || event->type() == QEvent::KeyRelease)
{
bool p_press = event->type() == QEvent::KeyPress;
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
if( keyEvent->isAutoRepeat() )
return;
switch (keyEvent->key())
{
case Qt::Key_Control:
//do something
break;
}
}
}
In the end, when I quickly press (and release) the ctrl button, I get as many as 4 QEvent triggers:
- QEvent::KeyPress
- QEvent::KeyPress
- QEvent::KeyRelease
- QEvent::KeyRelease
It turns out that each signal is generated twice. I can't understand anything. Why can it work like this? OC Win 10. Qt 5.8.0
c++
qt
qt5
0 Answers
Your Answer