Results 1 to 5 of 5

Thread: Making shortcut

  1. #1
    Join Date
    May 2007
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Making shortcut

    Hi,

    Im using PyQt, but it's a genral Qt4 question.

    In an old app (PyQt4.3), I used this to make a shortcut on the "Tab" key with:

    QtGui.QShortcut(QtGui.QKeySequence("Tab"), self.texteditor, self.doSomething)

    Now, it doesn't work anymore in v4.4 (are there any changes about that behaviour ?), ie QtGui.QKeySequence("Tab") does not respond and I'm forced to use another key at the same time, like QtGui.QKeySequence("Ctrl+Tab").

    So my question is simple : how do you set a shortcut on "Tab" key only ?

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Making shortcut

    The problem is probably that the tab key is associated to another action but that this is hardcoded (i.e done in a keyPressEvent and not through a QAction). The only way to work around this is to subclass the widget and reimplement the event handler according to your needs.
    Current Qt projects : QCodeEdit, RotiDeCode

  3. #3
    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: Making shortcut

    From QWidget docs:
    QWidget::keyPressEvent() is called whenever a key is pressed, and again when a key has been held down long enough for it to auto-repeat. Note that the Tab and Shift+Tab keys are only passed to the widget if they are not used by the focus-change mechanisms. To force those keys to be processed by your widget, you must reimplement QWidget::event().
    J-P Nurmi

  4. #4
    Join Date
    May 2007
    Posts
    22
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Making shortcut

    Thanks for the tip, I'll try to do that way.

  5. #5
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Making shortcut

    Another method that might be worth reimplementing for simplicity : QWidget::focusNextPrevChild()
    Current Qt projects : QCodeEdit, RotiDeCode

Similar Threads

  1. Button shortcut call an element in the menu
    By mourad in forum Qt Programming
    Replies: 5
    Last Post: 29th May 2008, 10:02
  2. Shortcut Context Problem
    By dvmorris in forum Qt Programming
    Replies: 4
    Last Post: 10th July 2007, 22:39
  3. disable/enable shortcut
    By harakiri in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2007, 10:58
  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

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.