Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Disable alt + tab
Qt 6.11 is out! See what's new in the release blog

Disable alt + tab

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • raghavangR Offline
    raghavangR Offline
    raghavang
    wrote on last edited by
    #1

    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:

    1. Disable Alt + Tab
    2. Lock the desktop screen to current view
      Is this possible using Python? Or is there any other way to achieve this requirement? Kindly Help.
    raven-worxR 1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      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

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      0
      • raghavangR raghavang

        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:

        1. Disable Alt + Tab
        2. Lock the desktop screen to current view
          Is this possible using Python? Or is there any other way to achieve this requirement? Kindly Help.
        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        @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 );
        }
        

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved