PDA

View Full Version : Qt::Key_Tilde?



ComServant
17th July 2011, 20:47
How do I catch a tilde keypress with Qt?


void MainWindow::keyPressEvent(QKeyEvent *event)
{
switch(event->key())
{
case Qt::Key_?????:
{
//do something...
} break;
default: break;
}
}

Qt defines 5 different Tilde keys (for accented charactors), and I can't find the right one I'm supposed to use.

The five are:
Qt::Key_AsciiTilde (I tried it, and can't seem to catch it)

Qt::Key_Atilde (These are for accented charactors - Didn't try them)
Qt::Key_Ntilde
Qt::Key_Otilde

Qt::Key_Dead_Tilde (Not sure what this is, but tried it, couldn't catch it).

Other keys work (I can catch Qt::Key_Escape), so I didn't mess up with the code itself. How do I catch the tilde key (the key under the Escape key on standard US Qwerty keyboards)?

mvuori
17th July 2011, 21:19
I'd do this first: To see if it is defined, press the key and see what integer value event->key() has and compare with http://doc.qt.nokia.com/latest/qt.html#Key-enum

ComServant
17th July 2011, 21:41
Yea, good idea.
It was giving me Qt::Key_QuoteLeft, but when I'm holding shift, it gives me Qt::Key_AsciiTilde.
Isn't event->text() for getting the textual representation? Shouldn't event->key() give the key irrespective of whether modifiers are pressed?

Am I handling keypresses wrong? How do I catch the key press itself?