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. Bring window to front -> raise(),show(),activateWindow() don't work on Windows
Forum Updated to NodeBB v4.3 + New Features

Bring window to front -> raise(),show(),activateWindow() don't work on Windows

Scheduled Pinned Locked Moved General and Desktop
29 Posts 9 Posters 60.9k Views 2 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.
  • H Offline
    H Offline
    Hedge
    wrote on last edited by
    #1

    I open a URL in the default-browser.
    Afterwards I want to bring the main-window of my application to the front again.

    I tried all approaches I could find but none worked. All it does is blink in the taskbar (of Window 7)
    Here's an example:

    @this->viewer->show();
    this->viewer->raise();
    this->viewer->activateWindow();@

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Peppy
      wrote on last edited by
      #2

      Why do you call viewer, not window instance?

      1 Reply Last reply
      0
      • H Offline
        H Offline
        Hedge
        wrote on last edited by
        #3

        I forgot to mention *viewer is a pointer to a QmlApplicationViewer which is derived from QDeclarativeView

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Chuck Gao
          wrote on last edited by
          #4

          Is the viewer a top-level window? Make sure it has no parent window.

          Chuck

          1 Reply Last reply
          0
          • H Offline
            H Offline
            Hedge
            wrote on last edited by
            #5

            It's the only window my program has.

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

              In windows, an application can't rais itself in front of the currently active window and it can't pull the focus to itself :-(
              What you can do is make it topmost (--> brings it to front) and remove tompost flag afterwards. But it will not get the input focus.

              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
              1
              • H Offline
                H Offline
                Hedge
                wrote on last edited by
                #7

                I don't care about input-focus as I only want to know my user to see that amazing QML-animation I crafted (and see that they succeeded to authorize my application to use Twitter).

                How do I make it topmost?

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

                  You should try:

                  @
                  Qt::WindowFlags eFlags = windowFlags ();
                  eFlags |= Qt::WindowStaysOnTopHint;
                  setWindowFlags(eFlags);
                  @

                  and then remove it again

                  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
                  • H Offline
                    H Offline
                    Hedge
                    wrote on last edited by
                    #9

                    Ah thanks. That works.

                    One general question though.
                    How do I remove the flag? I'm not much familiar with bit by bit manipulation.

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      DenisKormalev
                      wrote on last edited by
                      #10

                      @
                      eFlags &= ~Qt::WindowStaysOnTopHint;
                      @

                      1 Reply Last reply
                      0
                      • H Offline
                        H Offline
                        Hedge
                        wrote on last edited by
                        #11

                        Thank you but there must be something wrong with this code.
                        The window comes to the front and instantly gets hidden completely. It doesn't even show up in the taskbar anymore.

                        @ Qt::WindowFlags eFlags = this->viewer->windowFlags();
                        eFlags |= Qt::WindowStaysOnTopHint;
                        this->viewer->setWindowFlags(eFlags);
                        this->viewer->show();
                        eFlags &= ~Qt::WindowStaysOnTopHint;
                        this->viewer->setWindowFlags(eFlags);@

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          DenisKormalev
                          wrote on last edited by
                          #12

                          If you will look into assistant you will find there next info
                          "Note: This function calls setParent() when changing the flags for a window, causing the widget to be hidden. You must call show() to make the widget visible again."

                          So you need to call show() again after second setWindowFlags()

                          1 Reply Last reply
                          0
                          • H Offline
                            H Offline
                            Hedge
                            wrote on last edited by
                            #13

                            Ah, sorry.

                            The problem is that the window is behind the browser again after calling show() so if there isn't another solution I can only keep the window topmost (not really an option).

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

                              you can do it with windows API:

                              @
                              ::SetWindowPos(winID(), HWND_TOP, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW)
                              @

                              If this does not work, first call it with HWND_TOPMOST, and then this one.

                              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
                              • H Offline
                                H Offline
                                Hedge
                                wrote on last edited by
                                #15

                                Do I need to trigger something else as well?

                                I tried:

                                @ SetWindowPos(this->viewer->winId(), HWND_TOPMOST, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
                                SetWindowPos(this->viewer->winId(), HWND_TOP, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);@

                                but nothing happened.

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

                                  Hi Hege,

                                  I digged a bit, this is what I did:

                                  @
                                  // HACK: bringing window to top
                                  // 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();
                                      show();
                                      activateWindow();
                                  

                                  @

                                  This brings the window to front. Is your browser perhaps a topmost window? Or a child of yours?

                                  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
                                  • H Offline
                                    H Offline
                                    Hedge
                                    wrote on last edited by
                                    #17

                                    Hmm that doesn't work either.

                                    My browser is opened via QDesktopServices like this:

                                    @QDesktopServices::openUrl(openWebPageUrl);@

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

                                      perhaps that makes it a child of your window and therefore on top of your app.
                                      Can you bring your window to front by mouse?

                                      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
                                      • H Offline
                                        H Offline
                                        Hedge
                                        wrote on last edited by
                                        #19

                                        If the browser is not maximized, yes.

                                        1 Reply Last reply
                                        0
                                        • G Offline
                                          G Offline
                                          goetz
                                          wrote on last edited by
                                          #20

                                          I would kick out the native browser and put everything in a "QWebView":http://doc.qt.nokia.com/4.7/qwebview.html. You have control of the window then.

                                          Is there anything that hinders you from doing it this way (despite having to pack QtWebkit.dll and bloating the package)?

                                          http://www.catb.org/~esr/faqs/smart-questions.html

                                          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