Results 1 to 3 of 3

Thread: Problem detecting Ctrl Shortcut key

  1. #1
    Join Date
    Jan 2012
    Location
    Canary Islands, Spain
    Posts
    86
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Problem detecting Ctrl Shortcut key

    I have an app with a keyboard Shortcut reader.
    It works ok, detect Alt + Key, Shift + Key, etc. but when i try to detect Ctr + Key, Key is not a letter, is a strange character.
    Why is this happening?


    Here is the code:
    Qt Code:
    1. void rs_GetKey::keyPressEvent(QKeyEvent *kEvent) {
    2.  
    3. QStringList keySequence;
    4.  
    5. if (kEvent->modifiers() & Qt::ControlModifier) {
    6. keySequence << "Ctrl + ";
    7. }
    8. if (kEvent->modifiers() & Qt::AltModifier) {
    9. keySequence << "Alt + ";
    10. }
    11. if (kEvent->modifiers() & Qt::ShiftModifier) {
    12. keySequence << "Shift + ";
    13. }
    14.  
    15. keySequence << kEvent->text();
    16.  
    17. ui->label->setText(keySequence.join(""));
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 
    Always trying to learn >.<

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Problem detecting Ctrl Shortcut key

    Probably because, for example, Ctrl+A is mapped to the text "\x01", Ctrl+B to "\x02" and so on. However, since you don't tell what the actual values are I cannot be sure. If you want to know which key was pressed you should use QKeyEvent::key().

  3. #3
    Join Date
    Jan 2012
    Location
    Canary Islands, Spain
    Posts
    86
    Thanks
    4
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Problem detecting Ctrl Shortcut key

    if i use QKeyEvent::key(), it returns a numeric value (the number corresponding to each character).
    Is there any way to convert it to text on the fly, or i have to make my own QMap with a table of value/key?

    I'm doing: ui->label->setText( QStrng(kEvent->key() );

    It seems to work fine, but while i only press ctrl, it adds a "!" character, if i press only Alt modifier, adds a "#" character... would be possible ignore/remove these "ghost" characters?
    Last edited by aguayro; 1st August 2013 at 15:23.
    Always trying to learn >.<

Similar Threads

  1. shortcut key problem in Qpushbutton
    By BalaQT in forum Qt Programming
    Replies: 1
    Last Post: 12th April 2010, 09:16
  2. Shortcut: CTRL + SHIFT + "letters"
    By smarinr in forum Qt Programming
    Replies: 17
    Last Post: 22nd May 2009, 09:34
  3. shortcut problem on OSX
    By stefkeB in forum Qt Programming
    Replies: 0
    Last Post: 8th December 2008, 10:11
  4. Discovery free Shortcut CTRL+S on QTextBrowser
    By patrik08 in forum Qt Programming
    Replies: 0
    Last Post: 4th May 2007, 09:51
  5. Strange shortcut problem
    By blukske in forum Qt Programming
    Replies: 0
    Last Post: 13th March 2007, 10:26

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.