Results 1 to 2 of 2

Thread: Dialog loses focus/events when action is triggered

  1. #1
    Join Date
    Aug 2019
    Posts
    1
    Qt products
    Qt5 Qt/Embedded
    Platforms
    Unix/X11

    Default Dialog loses focus/events when action is triggered

    I have a Qt 5.4 application targeted for Ubuntu. I am trying to make a physical key do the same thing as a control on the touch screen. I am using a QAction. The touch is activated thru a signal/slot, I am trying to get the physical key activated through action->trigger();.

    In it, I have a parent class derived from QDialog that overrides event:

    Qt Code:
    1. class MyParentDialog : public QDialog
    2. {
    3. ...
    4. protected:
    5. virtual bool event (QEvent *event);
    6. ...
    7. }
    To copy to clipboard, switch view to plain text mode 
    And the class derived from it with a problem that also overrides event:

    Qt Code:
    1. class MyChildDialog : public MyParentDialog
    2. {
    3. ...
    4. protected:
    5. virtual bool event (QEvent *qEvent);
    6. ...
    7. }
    To copy to clipboard, switch view to plain text mode 

    Implementation:

    Qt Code:
    1. bool MyChildDialog::event (QEvent *qEvent)
    2. {
    3. qInfo()<<"MyChildDialog::event"<< qEvent->type();
    4.  
    5. switch (qEvent->type ())
    6. {
    7. case QEvent::KeyRelease:
    8. {
    9. QKeyEvent *keyEvt = nullptr;
    10. keyEvt = dynamic_cast<QKeyEvent *>(qEvent);
    11. int key = keyEvt->key();
    12. switch(key)
    13. {
    14. case KEY_CH1ON:
    15. {
    16. qInfo()<<"MyChildDialog::event KEY_CH1ON";
    17. bool currCheck = m_pActionRun->isChecked();
    18. m_pActionRun->trigger();
    19. bool afterCheck = m_pActionRun->isChecked();
    20. qInfo()<<"MyChildDialog::event KEY_CH1ON"
    21. <<currCheck<<afterCheck;
    22. return true;
    23. }
    24.  
    25. default:
    26. return MyParentDialog::event(qEvent);
    27. }
    28. }
    29. return true;
    30.  
    31. default:
    32. return MyParentDialog::event(qEvent);
    33. }
    34.  
    35. return true;
    36. }
    To copy to clipboard, switch view to plain text mode 

    If I comment out the line "m_pActionRun->trigger();", I get all events expected (qInfo() observation). If I include that line, I get all events until after the first KEY_CH1ON. After that, I only get paint events. The same action code works as expected repeatedly when activated through the touch screen signal/slot mechanism.

    The issue is that MyChildDialog loses focus when the action is triggered. Uncommenting the trigger line, if I press the hard key (KEY_CH1ON) again, the event goes to the parent of MyParentDialog. If I press the touch screen and then KEY_CH1ON again, MyChildDialog gets focus and gets the event as expected. I am running thru options, activateWindow(), setFocus(), at the end of the action slot code, but not working yet without the manual touch

    Thank you in advance for any guidance for kicking this dialog back into gear after the action completes.

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

    Default Re: Dialog loses focus/events when action is triggered

    Have you tried associating the key as the action's shortcut?

    Cheers,
    _

Similar Threads

  1. Find what event is triggered on an action
    By TEAmerc in forum Newbie
    Replies: 2
    Last Post: 1st October 2015, 18:33
  2. Replies: 1
    Last Post: 7th May 2015, 20:58
  3. action triggered no emit
    By waiter in forum Newbie
    Replies: 3
    Last Post: 27th September 2012, 23:26
  4. find out which shortcut triggered action
    By qt_gotcha in forum Newbie
    Replies: 3
    Last Post: 23rd August 2010, 20:27
  5. QWinwidget loses focus
    By salix in forum Qt Programming
    Replies: 0
    Last Post: 16th June 2009, 21:54

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.