PDA

View Full Version : QKeyEvent problem with different keyboard layout



minimoog
11th February 2010, 01:52
I have this problem with keyPressEvent handler.



void MainWindow::keyPressEvent(QKeyEvent *e)
{
if (e->key() == Qt::Key_N) {
//do some stuff
}

QMainWindow::keyPressEvent(e);
}


When my keyboard layout is English, when I press 'N' it's working ok, but when I change the layout to some other language (in my case macedonian) I don't receive that I'm pressing the 'N' button. (if statement fails)

Anyone know why is this? Is this a bug? Solution?

Thanks in advance,
Toni

franz
11th February 2010, 07:01
What is the key you receive using the other layout? Just check the value of e->key() for that.

minimoog
12th February 2010, 01:16
It's 1053 which is Cyrillic 'N'.

Now I am using QKeyEvent::nativeVirtualKey() which returns 'N' regardless of keyboard layout, but I am not sure is this very portable.

franz
12th February 2010, 06:45
Only one way to find out, I think.