Results 1 to 2 of 2

Thread: QLineEdit vs ApplicationShortcut

  1. #1
    Join Date
    Oct 2014
    Posts
    81
    Thanks
    20
    Thanked 9 Times in 9 Posts
    Qt products
    Qt5
    Platforms
    Windows
    Wiki edits
    7

    Default QLineEdit vs ApplicationShortcut

    I have a QAction with a shortcut set to letter "x", and the shortcut context Qt::ApplicationShortcut (at any point in the application the shortcut is available).
    When I click on a QLineEdit to start writing some text, all letters except "x" are read by this widget. The "x" will just activate the QAction.

    How can I use an application-wide shortcut like that in a way that makes it only available when the user isn't writing on a QLineEdit or other widget that receives text?
    Last edited by Kryzon; 18th August 2015 at 00:12.

  2. #2
    Join Date
    Oct 2014
    Posts
    81
    Thanks
    20
    Thanked 9 Times in 9 Posts
    Qt products
    Qt5
    Platforms
    Windows
    Wiki edits
    7

    Default Re: QLineEdit vs ApplicationShortcut

    To answer my own question, if you reimplement the "bool event( QEvent* event )" handler, you can catch QEvent::ShortcutOverride events that represent shortcut sequences that you want to interpret differently in the widget.

    Using this solved the problem:
    Qt Code:
    1. bool CustomLineEdit::event( QEvent* event )
    2. {
    3. switch( event->type() )
    4. {
    5. case QEvent::ShortcutOverride:
    6. event->accept();
    7. return true;
    8. break;
    9.  
    10. default: // Important to avoid compiler warnings about unhandled QEvent types.
    11. return QLineEdit::event( event );
    12. break;
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 
    Now the widget accepts "x" as text input when it has keyboard focus, and when it doesn't the QAction is invoked instead.
    More information here: http://wiki.qt.io/ShortcutOverride

Similar Threads

  1. Replies: 1
    Last Post: 12th October 2010, 23:20
  2. help with QLineEdit
    By benlyboy in forum Newbie
    Replies: 2
    Last Post: 18th February 2010, 02:39
  3. QLineEdit
    By rick_st3 in forum Newbie
    Replies: 1
    Last Post: 14th June 2008, 10:05
  4. About QLineEdit
    By vijay anandh in forum Newbie
    Replies: 2
    Last Post: 19th October 2006, 11:45

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.