PDA

View Full Version : pressing and holding a keyEvent



Alex22
5th March 2016, 15:27
Hi
How an event can be created by pressing and holding a key like "Ctrl" button on keyboard? For example:


keyPressingHoldingEvent(QKeyEvent * event)// is there any event function for pressing and holding a key?
{
if(event->key() == Qt::Key_Control)//if "Ctrl" is pressing and holding
//do something
else
//do some other thing (if "Ctrl" is not holding)
}

anda_skoa
5th March 2016, 16:14
You detect the press, then start a timer. if the release happens before the timer is through, it is a key press/release, if the timer fires, it is a press and hold.

Cheers,
_

Alex22
5th March 2016, 16:42
void keyPressEvent(QKeyEvent *keyP)
{
if(keyP->key()==Qt::Key_Control)
setCursor(Qt::ClosedHandCursor);
}

void keyReleaseEvent(QKeyEvent *keyR)
{
if(keyR->key()==Qt::Key_Control)
setCursor(Qt::CrossCursor);
}