Results 1 to 6 of 6

Thread: Qt 4.7.3 : Sub menu is not responding for key up/down event sent using QEvent

  1. #1
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Qt 4.7.3 : Sub menu is not responding for key up/down event sent using QEvent

    Dear All,

    In my application, when menu with sub menu is open , programmatically sending key up/down event is not working for the submenu.

    Sub menu is opened programmatically using following code

    Qt Code:
    1. QKeyEvent event(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier);
    2. QApplication::sendEvent(m_pSceneMenu, &event);
    To copy to clipboard, switch view to plain text mode 

    and first item of sub menu is also gets selected but after that sending further event is not working for the sub menu.

    if the same time (after displaying sub menu) using arrow keys from keyboard change sub menu selections.

    Please help if anyone has any idea.

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.7.3 : Sub menu is not responding for key up/down event sent using QEvent

    Are you sending the events to the correct recipient?

    Cheers,
    _

  3. #3
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 4.7.3 : Sub menu is not responding for key up/down event sent using QEvent

    If I give sub menu handle then it sends event correctly but then in case if i have more than one sub menu its very difficult to identify which sub menu is currently open because all sub menu returns true for isVisible.

    Thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.7.3 : Sub menu is not responding for key up/down event sent using QEvent

    Have you checked hasFocus()?

    Cheers,
    _

  5. #5
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt 4.7.3 : Sub menu is not responding for key up/down event sent using QEvent

    You are correct, hasFocus returns false.

    Sending return key press event to menu, if menu item is submenu it opens sub menu but doesn't set focus. below is the code i used to simulate return key press.

    Qt Code:
    1. QKeyEvent event(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier);
    2. QApplication::sendEvent(m_pSceneMenu, &event);
    To copy to clipboard, switch view to plain text mode 

    But one more important point is once the sub menu is open, after that sending key event programmatically is not working but at the same time pressing arrow keys on keyboard changes the selection on sub menu.

    Thank you for your useful tips but can you suggest me something to set focus on sub menu.

    Thanks.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt 4.7.3 : Sub menu is not responding for key up/down event sent using QEvent

    Interesting.
    Normal keyboard handling requires focus, so if navigating the sub menu with the keyboard works it should have focus.

    Anyway, if the focus can not be used to determine the currently open sub menu, then you'll have to decide based on which key you have sent.

    Alternatively you could try sending the events to the application object and see if its overall key handling code moves focus through the menu hierarchy.

    Cheers,
    _

Similar Threads

  1. if(event->type() == QEvent::KeyRelease) gives error
    By schooner in forum Qt Programming
    Replies: 2
    Last Post: 20th March 2014, 16:51
  2. Replies: 1
    Last Post: 1st December 2011, 21:47
  3. QEvent::KeyPress problem, when will this event appear?
    By batileon in forum Qt Programming
    Replies: 11
    Last Post: 17th June 2011, 05:23
  4. [Qt4.5] event(QEvent * event) freeze application
    By czlowiekcien in forum Newbie
    Replies: 2
    Last Post: 25th May 2009, 20:25
  5. event(QEvent * event)
    By rajaraob in forum Qt Programming
    Replies: 9
    Last Post: 26th February 2007, 20:25

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.