Results 1 to 2 of 2

Thread: QKeyEvent::matches

  1. #1
    Join Date
    Mar 2014
    Location
    USA
    Posts
    85
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default QKeyEvent::matches

    Is there a way to make QKeyEvent::matches(QKeySequence::StandardKey) work with a non-standard QKeySequence, for example ctrl+K, or is there another function I'm not seeing? I'm trying to set up where the user can define their own key sequence in a settings window, pass that QKeySetting into the mainwindow as a QVariant string, and then check against it on a keypress event in the main window.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QKeyEvent::matches

    Is there a way to make QKeyEvent::matches(QKeySequence::StandardKey) work with a non-standard QKeySequence
    It doesn't look like it, but all you really need to do in the keyPressEvent is to check the values of QKeyEvent::key() and QKeyEvent::modifiers() for the values Qt::Key_K and Qt::ControlModifier respectively for the example you gave of CTRL+K.

    You may need to be careful if the user redefines a standard key sequence - this could cause unexpected behavior if your event handler doesn't "eat" the sequence but also passes it along to the keypress handler for the base class.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 4
    Last Post: 29th February 2012, 09:06
  2. Replies: 4
    Last Post: 21st June 2011, 12:05
  3. Replies: 1
    Last Post: 10th March 2010, 18:19
  4. Something about the QKeyEvent in Qt3
    By cspp in forum Qt Programming
    Replies: 1
    Last Post: 30th June 2009, 02:38
  5. QKeyEvent
    By sonuani in forum Newbie
    Replies: 8
    Last Post: 25th February 2008, 07:38

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.