Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. '#' key press not returning Qt::Key_NumberSign on Mac
Forum Updated to NodeBB v4.3 + New Features

'#' key press not returning Qt::Key_NumberSign on Mac

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 202 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • AndyBriceA Offline
    AndyBriceA Offline
    AndyBrice
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • jeremy_kJ Offline
      jeremy_kJ Offline
      jeremy_k
      wrote on last edited by
      #2

      QKeyEvent::text() should return QString("#").

      Asking a question about code? http://eel.is/iso-c++/testcase/

      1 Reply Last reply
      5
      • AndyBriceA Offline
        AndyBriceA Offline
        AndyBrice
        wrote on last edited by
        #3

        @ jeremy_k
        That's what I was looking for - Thanks!

        1 Reply Last reply
        0
        • AndyBriceA AndyBrice has marked this topic as solved on

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved