Results 1 to 3 of 3

Thread: Qt::Key_Tilde?

  1. #1
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Qt::Key_Tilde?

    How do I catch a tilde keypress with Qt?

    Qt Code:
    1. void MainWindow::keyPressEvent(QKeyEvent *event)
    2. {
    3. switch(event->key())
    4. {
    5. case Qt::Key_?????:
    6. {
    7. //do something...
    8. } break;
    9. default: break;
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    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)?

  2. #2
    Join Date
    May 2011
    Posts
    239
    Thanks
    4
    Thanked 35 Times in 35 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: Qt::Key_Tilde?

    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

  3. The following user says thank you to mvuori for this useful post:

    ComServant (17th July 2011)

  4. #3
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt::Key_Tilde?

    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?

Tags for this Thread

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.