Results 1 to 5 of 5

Thread: Handling of dead keys in keyPressEvent()

  1. #1
    Join Date
    Nov 2006
    Location
    Dresden, Germany
    Posts
    108
    Thanks
    9
    Thanked 12 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Handling of dead keys in keyPressEvent()

    Hi there,

    I wan't to capture key presses, including dead keys. So for instance, if you press ~ and afterwards n, you get ñ (at least on a spanish keyboard layout).

    When I reimplement keyPressEvent() in my widget, I get however always the ~ and n separately. I would rather get only one keyPressEvent() with the complete character.

    How would I best do this?
    Bye,
    Andreas

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Handling of dead keys in keyPressEvent()

    You'll always get two key press events, because at the time when '~' is pressed there is no way telling if something else is going to be pressed as well, so the event has to be triggered. As for the composed character, it should be available in QKeyEvent::text() during the second key event.

  3. #3
    Join Date
    Nov 2006
    Location
    Dresden, Germany
    Posts
    108
    Thanks
    9
    Thanked 12 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Handling of dead keys in keyPressEvent()

    This is however not what I observe. I receive a keyPressEvent() after the dead key was pressed and can detect that correctly when comparing the event->key() with for instance Qt::Key_Dead_Tilde. However, regardless whether I accept or ignore this event, the next keypress event will just give me the plain character. So event->text() contains a "n" instead of a "ñ".

    Any suggestions?
    Andreas

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Handling of dead keys in keyPressEvent()

    Try setting Qt::WA_KeyCompression flag for widget that receives those key events.

  5. #5
    Join Date
    Nov 2006
    Location
    Dresden, Germany
    Posts
    108
    Thanks
    9
    Thanked 12 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Handling of dead keys in keyPressEvent()

    Got it to work. The handling of dead keys is directly linked to the keyboard layout selected. I wrote a small test program and tested it on windows and linux and apparently the settings in the X-Windows system were the problem.

    Anyway, if the keyboard layout is correctly set up, Qt doesn't generate a keypressevent for dead keys, but only for the fully composed key. I also tried the compression flag, but it didn't make any difference. It really only depends on the keyboard settings (dead keys are also different from language to language).

    Thanks again for the suggestions!
    Andreas

  6. The following user says thank you to ghorwin for this useful post:

    sunil.thaha (4th December 2006)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.