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. [Solved: Working as Expected] Bringing the application window to the front of all other applications on desktop.
Forum Updated to NodeBB v4.3 + New Features

[Solved: Working as Expected] Bringing the application window to the front of all other applications on desktop.

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

    I have no idea if this discussion has another resolved thread or not, but I couldn't find a solution any where. My requirement is one of my Qt application listens to another using QLocalServer and on new connection it would bring itself to the front of all other applications on desktop. I have used the following code which works fine only if my application windows is minimized. But if my application window is behind any other windows, then it just flashes on the taskbar.

    setWindowState( (windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
    activateWindow();
    raise();
    setFocus();

    Please reply the solution if anybody knows/redirect me to any specific thread which has the resolution.

    Thanks,
    Adaita.

    C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg. -- Bjarne Stroustrup

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      QMartin
      wrote on last edited by
      #2

      Hello!

      I think "this":http://www.qtcentre.org/threads/22197-Bring-application-window-to-front could help you

      Regards

      1 Reply Last reply
      0
      • adaitabeheraA Offline
        adaitabeheraA Offline
        adaitabehera
        wrote on last edited by
        #3

        Thanks Martin, but I have already visited this link. It didn't help. Also I don't want mix native APIs with Qt APIs. I am looking for a solution that can be done using only Qt functions.

        C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg. -- Bjarne Stroustrup

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MuldeR
          wrote on last edited by
          #4

          I think it's an intentional restriction of the Windows API that applications cannot always "steal" focus. If the application icon "flashes" on the taskbar, it means that Windows just decided that the application is not allowed to steal focus right now and that the user can switch to that application as soon as he prefers...

          However you can create a "top most" window, that will stay on top, regardless of whether it has focus or not.

          Try:
          @setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint)@

          My OpenSource software at: http://muldersoft.com/

          Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

          Go visit the coop: http://youtu.be/Jay...

          1 Reply Last reply
          0
          • adaitabeheraA Offline
            adaitabeheraA Offline
            adaitabehera
            wrote on last edited by
            #5

            Thanks MuldeR, but Qt::WindowStaysOnTopHint flag will always make the application to stay on the top always, which I don't want. I do not understand why there should be a restriction. VLC Media player is also developed using Qt, then how does it work for the similar scenario? Does it use the native windows API to do so? If it is so, then why can't Qt support a wrapper cross API for the same?

            I am looking forward to getting some solution guys...

            C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg. -- Bjarne Stroustrup

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MuldeR
              wrote on last edited by
              #6

              As said before, this is a restriction of the underlying Win32 API, which Qt unavoidably has to use (on Win32).

              I think the docs are quite clear:
              http://msdn.microsoft.com/en-us/library/windows/desktop/ms633539(v=vs.85).aspx
              (See remarks section!)

              bq. An application cannot force a window to the foreground while the user is working with another window. Instead, Windows flashes the taskbar button of the window to notify the user.

              This is because otherwise multiple processes might try to "steal" focus at the same time, which would lead to the focus jumping between different applications all the time, making the system unusable!!!

              BTW: I never noticed VLC Player brings itself to the foreground, while I'm working with other applications. But if you refer to the "notification" banner that pops up now and then, that's probably a "top most" window which they only show when needed (while the VLC Player "main window" certainly is NOT top-most).

              It definitely is possible to have a "top most" child window without making your "main" window top-most too.

              My OpenSource software at: http://muldersoft.com/

              Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

              Go visit the coop: http://youtu.be/Jay...

              1 Reply Last reply
              0
              • adaitabeheraA Offline
                adaitabeheraA Offline
                adaitabehera
                wrote on last edited by
                #7

                Thanks MuldeR. I got it now. It is quite clear now.

                C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do, it blows away your whole leg. -- Bjarne Stroustrup

                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