Results 1 to 5 of 5

Thread: How catch key press and key release for entire application

  1. #1
    Join Date
    Dec 2009
    Posts
    62
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default How catch key press and key release for entire application

    Is it possible to catch key up and key down on application level meaning before they are handled by the widgets? I want to be able to press a key for a while and then release it regardless of which widget that has the focus. Is there a generic way to do this, I am currently trying on Win32 and I tested inhereting keyPressed and keyReleased in my QMainWindow class and it works but as soon as a Widget has focus for instance if an element i selected in a list view the keyPressed event does not get to the MainWindow, the keyReleased event does however for some reason.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: How catch key press and key release for entire application

    You might want to try an event filter.

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How catch key press and key release for entire application

    You can search for flick charm example in Qt Labs... it also used event filters.
    It will give you an idea how to stack events and perform required action.

  4. #4
    Join Date
    Dec 2009
    Posts
    62
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How catch key press and key release for entire application

    I saw some replies on this and I have now tried the event filter but I get the exact same result. keyReleased event is passed as an event but keyPressed is not. I always get the keyReleased but not keyPressed. My only guess is that the keyPressed is taken by the QTreeView which currently has focus however I have also tried to add an event filter to the class that contains the QTreeView but that did not help. Do I have to inherit the QTreeView in order to intercept the keyPressed event with the eventfilter or is there another way to prevent the QTreeView from stealing my keypresses. This issue does not seem to exist on Symbian, only Win32.

  5. #5
    Join Date
    Dec 2009
    Posts
    62
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How catch key press and key release for entire application

    I misunderstood the eventFilter approach and installed it on my class instead of the TreeView. I think I get how it works now. I can recommend this:
    http://www.qtcentre.org/threads/25487-Detect-Arrow-Keys
    post. I just missed the first line, where the filter was installed, in the post which was very important.

Similar Threads

  1. QMessageBox closes entire application
    By Leoha_Zveri in forum Qt Programming
    Replies: 2
    Last Post: 19th September 2009, 12:44
  2. Replies: 6
    Last Post: 5th August 2009, 11:40
  3. How to catch CTRL+Y in application
    By Morea in forum Qt Programming
    Replies: 1
    Last Post: 29th April 2009, 07:14
  4. Qprocess...hanging entire application!!!!
    By nupul in forum Qt Programming
    Replies: 5
    Last Post: 10th May 2006, 15:24
  5. how to catch enter press in QLabel?
    By Morea in forum Newbie
    Replies: 2
    Last Post: 26th March 2006, 23:53

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.