Calling a functions that changes the GUI of an QAxWidget makes the caller loose focus. How can I avoid this?
Asked
Active
Viewed 67 times
1 Answers
0
Certain actions make Windows transfer the active window state to another window / application. When you trigger one of them your ActiveX application becomes active and therefore you loose focus in your client application.
To avoid this use can write a scope guard that resets the focus to your client after Windows has wrongly transferred the active state:
class AxFocusScopeGuard
{
public:
AxFocusScopeGuard(QWidget* parentWidget)
: m_focusedWidget(parentWidget->focusWidget())
{ }
~AxFocusScopeGuard()
{
QCoreApplication::processEvents();
if(m_focusedWidget)
m_focusedWidget->setFocus();
}
private:
QWidget* m_focusedWidget = nullptr;
};
void ActiveXCallHandler::updateGuiActiveX()
{
AxFocusScopeGuard guard(m_parentWidget);
axWidget->dynamicCall("updateYourGui()");
}

jaba
- 735
- 7
- 18