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. ActivateWindow() does not send window to front
Forum Updated to NodeBB v4.3 + New Features

ActivateWindow() does not send window to front

Scheduled Pinned Locked Moved General and Desktop
11 Posts 5 Posters 33.3k 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.
  • L Offline
    L Offline
    lyuts
    wrote on last edited by
    #2

    Here is how I do it:

    @showNormal();
    raise();
    activateWindow();@

    and my window has Qt::Popup flag set.

    I'm a rebel in the S.D.G.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      blex
      wrote on last edited by
      #3

      Thank you, I will try this sequence.

      I think that in most cases it works. I will try to describe the case when it doesn't work.


      Oleksiy Balabay

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lyuts
        wrote on last edited by
        #4

        I use this sequence in my timer and I had no problems with it. Every time the timer fired, the timer window popped up as needed. But if you find the use case when it doesn't work, I will investigate it.

        I'm a rebel in the S.D.G.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #5

          if your main window is in the background and you want to activate it with a qsingleapp, you will have problems bringing the window to the front.
          An application can't pull the focus on windows. and activate and rais will bring it to front in some cases but not in all :-( That's why we have this HACK:

          @ // THIS IS A HACK:
          // from QT documentation:
          // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          // void QWidget::activateWindow ()
          // ...
          // On Windows, if you are calling this when the application is not currently
          // the active one then it will not make it the active window. It will change
          // the color of the taskbar entry to indicate that the window has changed in
          // some way. This is because Microsoft do not allow an application to
          // interrupt what the user is currently doing in another application.
          // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          // This hack does not give the focus to the app but brings it to front so
          // the user sees it.
          ::SetWindowPos(effectiveWinId(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
          ::SetWindowPos(effectiveWinId(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
          // HACK END

          raise();
          pWidget->show();
          // pWidget->setFocus(); this does not work :-(
          pWidget->activateWindow();
          pWidget->raise();
          

          @

          It always brings the window to the front, but the focus is somewhere in the system :-( In some other app...

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • B Offline
            B Offline
            blex
            wrote on last edited by
            #6

            [quote author="Gerolf Reinwardt" date="1290760605"]That's why we have this HACK[/quote]

            Thank you for code.

            Sorry, but what OS is the target of this hack? I have solved the problem on Windows with the similar code. I need solution for Linux.


            Oleksiy Balabay

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #7

              That is only for windows, but handles also cases, where rais does sometime not work.
              I think, for linux, you have to do something like the win 32 call to SetWindowPos(Toplevel) with X11 calls. I didn't find a solution that works without platform specific code. If you look at the code of QWidget setting topmost, you could find how it works on linux and try that out...

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • B Offline
                B Offline
                blex
                wrote on last edited by
                #8

                [quote author="Gerolf Reinwardt" date="1290761338"]If you look at the code of QWidget setting topmost, you could find how it works on linux and try that out...[/quote]

                Thanks. Already done without any success :)


                Oleksiy Balabay

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  blex
                  wrote on last edited by
                  #9

                  [quote author="lyuts" date="1290759622"]Here is how I do it:

                  @showNormal();
                  raise();
                  activateWindow();@

                  and my window has Qt::Popup flag set.[/quote]

                  Thank you for advice. I cannot reproduce bug with this code. Now I am going to handle the application to our QA team and to wait for results :)


                  Oleksiy Balabay

                  1 Reply Last reply
                  0
                  • B blex

                    I use qtsingleapplication solution to ensure that only one instance of the application is running.

                    When the second instance is started then it sends message to the already running process.

                    Already running process should bring it's window to front. How to achieve this?

                    I used activateWindow() and raise() but it is not a solution (and not a Qt bug - this is the limitation described in the documentation). These calls just "highlight" window in task bar.

                    I found solution for Windows.

                    I cannot find solution for Linux. I am interesting in GNOME on Suse Linux (SLED 10).

                    Does anybody solved this issue?

                    M Offline
                    M Offline
                    macri
                    wrote on last edited by
                    #10

                    @blex
                    In linux i use this:

                    if(!this->isActiveWindow()){
                    this->setWindowFlags((windowFlags() & Qt::WindowStaysOnTopHint));
                    this->setWindowFlags((windowFlags() & ~Qt::WindowStaysOnTopHint));
                    this->show();}

                    1 Reply Last reply
                    1
                    • B Offline
                      B Offline
                      Boan Smith
                      wrote on last edited by Boan Smith
                      #11

                      I use this in windows, it works

                          Qt::WindowFlags flags = windowFlags();
                          this->setWindowFlags((flags | Qt::WindowStaysOnTopHint));
                          this->showMaximized();
                          this->setWindowFlags(flags);
                          this->showMaximized();
                      
                      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