'#' key press not returning Qt::Key_NumberSign on Mac
Unsolved
General and Desktop
-
If I press the '#' key on my Windows PC (with UK keyboard) this code:
void MainWindow::keyPressEvent( QKeyEvent* event ) { QMainWindow::keyPressEvent( event ); qDebug() << "event->key()=" << event->key(); qDebug() << "event->modifiers()=" << event->modifiers(); }
Outputs:
Qt::Key_NumberSign Qt::NoModifier
As, expected.
But if I press Option-3 to get the '#' key on my Mac (with UK keyboard) the same code gives:
Qt::Key_3 Qt::AltModifier
Instead of Qt::Key_NumberSign.
This behaviour is not great because it means that I am going to get different codes on different Mac keyboard layouts.
I don't really want to have to do something ugly like this to trap '#' press on both Windows or Mac:
if ( event->key() == Qt::Key_NumberSign #ifdef Q_OS_MACX || ( event->key() == Qt::Key_3 && ( ( event->modifiers() & Qt::AltModifier ) || ( event->modifiers() & Qt::ShiftModifier ) ) ) #endif ) { ... }
Is there a cleaner way?