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. QMainWindow, Alt Tab Behavior
Forum Updated to NodeBB v4.3 + New Features

QMainWindow, Alt Tab Behavior

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 5.7k 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.
  • W Offline
    W Offline
    Wargamer
    wrote on last edited by
    #1

    When the user presses alt tab, i would like the application to minimize itself to the system tray. Instead what happens is the window remains open and moves to the back.

    How can I handle this within Qt itself? I have a separate thread running which can implement a hot-fix if need be. How can I identify this state, so as to call "showWindowMinimized()" on my QMainWindow? I did succeed in implementing a partial solution, the problem is it incorrectly fires when trying to open the window, which prevents the window from being open on certain test systems depending on the windows behavior.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      You can use QWidget::focusOutEvent() (the reason will be Qt::ActiveWindowFocusReason), just make sure your focusPolicy is not Qt::NoFocus, to detect if the QMainWindow is no longer the active window.

      If you want to know if you have been specifically focused-out by Alt+Tab you will have to use platform-specific code.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        tobias.hunger
        wrote on last edited by
        #3

        Alt-Tab is usually handled by the system before it ever reaches the application.

        You might be able to minimize once the application uses focus or something. Not sure whether that is the beaviour you want though.

        1 Reply Last reply
        0
        • W Offline
          W Offline
          Wargamer
          wrote on last edited by
          #4

          @ Tobias

          Yes i want to minimize once the application loses focus. But again, how do i get that event.

          1 Reply Last reply
          0
          • W Offline
            W Offline
            Wargamer
            wrote on last edited by
            #5

            @ Lukas

            No, I don't get a QWidget::focusOutEvent() when I press alt tab. I did set the focus policy to Qt::WheelFocus, which is the strongest of them all, and I am still not getting the event.

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #6

              You should. Are you sure that your event handler has the correct signature (and you are not declaring a new method instead of overriding it)?

              @
              void MainWindow::focusOutEvent(QFocusEvent *event)
              {
              if (event->reason() == Qt::ActiveWindowFocusReason)
              ...

              return QMainWindow::focusOutEvent(event);
              

              }
              @

              1 Reply Last reply
              0
              • W Offline
                W Offline
                Wargamer
                wrote on last edited by
                #7

                Thanks a lot, I finally got it working. Had implemented a temporary work around, and then forgot about it since it wasn't top priority.

                The problem was the event was going to the QDeclarativeView, not to the QMainWindow. When I added the code to the underlying view class it worked perfectly.

                Thanks,

                Wargamer

                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