문제

I press the Ctrl key. My first function works fine:

void MainWindow::keyPressEvent(QKeyEvent *event){
    if(event->modifiers()==Qt::CTRL){               //RETURNS TRUE
        ui->widget->groupmaking=true;
    } }

In the second, i have troubles with checking what kind of key was released. (It was Ctrl)

void MainWindow::keyReleaseEvent(QKeyEvent *event){
    if(event->modifiers()==Qt::CTRL){               //RETURNS FALSE. WHY?
        ui->widget->groupmaking=false;
        ui->widget->groupexist=true;
    }
}

So, how to catch Ctrl release correctly ?

도움이 되었습니까?

해결책

The reason for such behavior is that there is no key modifier at the moment, when you get the key release event, because the Ctrl key is already released. The right way to perform such a check would be:

void keyReleaseEvent(QKeyEvent *event)
{
    if(event->key() == Qt::Key_Control) {
        [..]
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top