Variable increment / decrement by pressing the QkeyEvent button
-
Hi,
I created a class that aims to increment the variable "x" in the range 0-100 when pressing the "W" button on the keyboard. However, I would like the variable to slowly decrease to zero after releasing the button. During the increment / decrementation, I would like to introduce a delay. Does anyone know how to do it? My current code:
void MoveControler::keyPressEvent(QKeyEvent *event) { try { if(event->key() ==Qt::Key_W){ x+=1; } } catch (QString exception) { QMessageBox::about(nullptr, "Error", exception); } }
-
Hi,
I created a class that aims to increment the variable "x" in the range 0-100 when pressing the "W" button on the keyboard. However, I would like the variable to slowly decrease to zero after releasing the button. During the increment / decrementation, I would like to introduce a delay. Does anyone know how to do it? My current code:
void MoveControler::keyPressEvent(QKeyEvent *event) { try { if(event->key() ==Qt::Key_W){ x+=1; } } catch (QString exception) { QMessageBox::about(nullptr, "Error", exception); } }