Results 1 to 8 of 8

Thread: Cannot capture Key_Up

  1. #1
    Join Date
    Aug 2009
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Cannot capture Key_Up

    Hi,

    I have a QWidget subclass (call it Foo) that holds a child GraphicsView and GraphicsScene. I've added Foo as the central widget to a MainWindow object and cannot capture the key press event for Key_Up. I have a feeling this has to do with focus handling as I see all other key strokes. I've sniffed all the events to the Foo widget and can see QEvent::ShortcutOverride when the Up arrow is depressed and KeyRelease when the key is released.

    The keyPressEvent() works perfectly fine in the GraphicsView.

    Any thoughts on how to enable this?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cannot capture Key_Up

    You have to set the focus policy and optionally focus proxy for your widgets appropriately.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Aug 2009
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Cannot capture Key_Up

    Thanks for the reply. I played around with the focus proxy and policy but still cannot get it to work.

    Do I call MainWindow->setFocusProxy(Foo Widget)? and MainWindow->setFocusPolicy(Qt::NoFocus) ?

    Leaving everything else alone on the Foo Widget. My Foo Widget children (GraphicsView/Scene) are still receiving the event correctly.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cannot capture Key_Up

    What's the focus policy of the widget you want to capture the key in?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Aug 2009
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Cannot capture Key_Up

    Everything is set to default.

    I'm assuming the MainWindow and centralwidget() configuration do something to intercept the Up/Down Keys.

    I figured that's why I get the QEvent::ShortcutOverride event when I press the Up/Down key while sniffing the Foo widget's events.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cannot capture Key_Up

    Quote Originally Posted by xenome View Post
    Everything is set to default.

    I'm assuming the MainWindow and centralwidget() configuration do something to intercept the Up/Down Keys.
    Default focus policy of QWidget (and QMainWindow as well) is NoFocus.

    Your widget simply doesn't have focus so it won't receive key events. If you want something to happen on a specific key combination you can register a shortcut for that combination - this is done via QShortcut (of course you still won't receive a keyPressEvent in your widget).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Aug 2009
    Posts
    32
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Cannot capture Key_Up

    Well I would think it has some focus as I receive all key events except the arrows.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Cannot capture Key_Up

    Please provide a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 3
    Last Post: 5th July 2009, 17:22
  2. synchronise QLabel display and webcam capture
    By fbmfbm in forum Qt Programming
    Replies: 2
    Last Post: 24th February 2009, 11:10
  3. capture screen (with Mouse) ?
    By ascii in forum Qt Programming
    Replies: 3
    Last Post: 12th November 2008, 12:16
  4. How to capture a window?
    By Misenko in forum Qt Programming
    Replies: 2
    Last Post: 12th September 2008, 15:36
  5. Capture a keyboard event
    By mahe2310 in forum Qt Programming
    Replies: 8
    Last Post: 16th February 2006, 11:19

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.