Results 1 to 3 of 3

Thread: Getting real key in keyPressEvent

  1. #1
    Join Date
    Oct 2007
    Location
    Quebec, Canada
    Posts
    40
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Getting real key in keyPressEvent

    I want to develop a control that listen for keyPressEvent and displays the key combination entered. For example, if control and O is pressed, I want to display Ctrl + O.

    I found a way to do this using a dummy QKeySequence to translate Qt::Key to string. However, when I hit Shift and ; I get "Shift + :" in the string returned. Is there a way when retrieving the key in key press event(or any other event) to not get the result of the key combination ?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Getting real key in keyPressEvent

    Here's something to start with:
    Qt Code:
    1. int key = event->key();
    2. int modifiers = event->modifiers();
    3. if (key >= Qt::Key_Shift && key <= Qt::Key_Alt)
    4. key = 0;
    5. qDebug() << QKeySequence(modifiers ? modifiers : key, modifiers ? key : 0).toString().remove(", ");
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. #3
    Join Date
    Oct 2007
    Location
    Quebec, Canada
    Posts
    40
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Getting real key in keyPressEvent

    This will also display "Shift :" instead of "Shift ;". The thing is the key gets translated before I get it. I would understand the text() function to return ':' if shift was pressed with ';' but the key() function should return Qt::Key_SemiColon right ?

Similar Threads

  1. QTreeWidget keyPressEvent
    By hgedek in forum Qt Programming
    Replies: 3
    Last Post: 18th August 2007, 17:33
  2. F2 keyPressEvent Not Capturing
    By Rayven in forum Qt Programming
    Replies: 1
    Last Post: 2nd August 2007, 21:41
  3. Displaying real time images
    By Sheetal in forum Qt Programming
    Replies: 9
    Last Post: 22nd February 2007, 12:29
  4. Handling of dead keys in keyPressEvent()
    By ghorwin in forum Qt Programming
    Replies: 4
    Last Post: 2nd December 2006, 13:26
  5. KeyPressEvent behaves strange, skips the F key.
    By pir in forum Qt Programming
    Replies: 1
    Last Post: 18th August 2006, 18:07

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.