Disable alt + tab
-
Hi all,
I do not want the users of my Qt Desktop app to navigate away from the application for a time until they fill out the form. I was thinking of a few ways:- Disable Alt + Tab
- Lock the desktop screen to current view
Is this possible using Python? Or is there any other way to achieve this requirement? Kindly Help.
-
There is no reliable way to achieve this. ctr+alt+del on windows will be able to circumvent any lock you can possibly put on your app.
The closes thing achievable is to have a loseFocus event on your main window that signals that alt-tab was activated and to behave accordigly.
For example if your app is a quiz if someone tries to google the answer you can strike the question as invalid -
Hi all,
I do not want the users of my Qt Desktop app to navigate away from the application for a time until they fill out the form. I was thinking of a few ways:- Disable Alt + Tab
- Lock the desktop screen to current view
Is this possible using Python? Or is there any other way to achieve this requirement? Kindly Help.
@raghavang
You can overrride QWidget::focusNextPrevChild() and return true in case the form data isn't complete yet.
But this is by far not a general solution.
Also you won't prevent that the focus WILL get lost by the OS for some other reason.You could install an event filter on the QApplication and listen to focus-in events and set the focus back to the last known form widget in case the focus is set outside the form.
bool eventFilter( QObject* watched, QEvent* event ) { switch( evnet->type() ) { case QEvent::FocusIn: { if( QWidget* w = qobject_cast<QWidget*>(watched) ) { if( ! m_MyForm->isAncestorOf( w ) ) QMetaObject::invokeMethod( m_LastKnownFormWidget, "setFocus", Qt::QueuedConnection ); // queued connection to avoid invalid focus state in your application } } break; } return BaseClass::eventFilter( watched, event ); }