PDA

View Full Version : QKeyEvent and getting all 'F' key presses



taraj
15th June 2020, 12:49
Hi,

Just wondering if there is a way to single out all the 'F' keys (F1 through to F12) in one go when I have a keyPressEvent(QKeyEvent *k) without having to list then all like this

if(k->key() == Qt::Key_F1)
if(k->key() == Qt::Key_F2)
etc...

Thank you very much :)

Lesiok
15th June 2020, 13:40
if(k->key() >= Qt::Key_F1 && k->key() <= Qt::Key_F12)

taraj
16th June 2020, 00:16
Thank you very much. I was unsure if the < > could be used in this case.

cheers!!

Lesiok
16th June 2020, 09:16
In this case you can. If the set of tested values is discontinuous, you can define static QVector<int> with all values and use the QVector::indexOf method