PDA

View Full Version : Dialog loses focus/events when action is triggered



JulieC
20th August 2019, 22:52
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:


class MyParentDialog : public QDialog
{
...
protected:
virtual bool event (QEvent *event);
...
}

And the class derived from it with a problem that also overrides event:


class MyChildDialog : public MyParentDialog
{
...
protected:
virtual bool event (QEvent *qEvent);
...
}

Implementation:


bool MyChildDialog::event (QEvent *qEvent)
{
qInfo()<<"MyChildDialog::event"<< qEvent->type();

switch (qEvent->type ())
{
case QEvent::KeyRelease:
{
QKeyEvent *keyEvt = nullptr;
keyEvt = dynamic_cast<QKeyEvent *>(qEvent);
int key = keyEvt->key();
switch(key)
{
case KEY_CH1ON:
{
qInfo()<<"MyChildDialog::event KEY_CH1ON";
bool currCheck = m_pActionRun->isChecked();
m_pActionRun->trigger();
bool afterCheck = m_pActionRun->isChecked();
qInfo()<<"MyChildDialog::event KEY_CH1ON"
<<currCheck<<afterCheck;
return true;
}

default:
return MyParentDialog::event(qEvent);
}
}
return true;

default:
return MyParentDialog::event(qEvent);
}

return true;
}


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.

anda_skoa
24th August 2019, 08:35
Have you tried associating the key as the action's shortcut?

Cheers,
_