Results 1 to 14 of 14

Thread: Bring application window to front

  1. #1
    Join Date
    Jun 2009
    Posts
    10

    Default Bring application window to front

    Hello.
    I have a some problem: I need to bring a QT application main window to front. It should become on the top of all windows (active and topmost).

    I send a special message to my application (e.g. WM_USER_BRING_TO_TOP) and get the main window HWND (through winId()).
    After this, i tried BringWindowToTop(), SetActiveWindow(), SetForegroundWindow(), set window style to WS_EX_TOPMOST, set window position to HWND_TOPMOST, but it all did not brought window to top. The only thing i've got was a flashing window on the taskbar.

    Can anyone help me to understand why? Can you suggest a decision?

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Bring application window to front

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2009
    Posts
    10

    Default Re: Bring application window to front

    No..))) It's not just simple as you can imagine I tried this many times...

    The message is sent from another application. The methods raise(), activateWindow(), ... does not works. The window is only flashing on the taskbar. They does not change z-order of window and doesn't bring it to front. Probably, it was because there were a topmost window on my desktop...But i believe, that the decision exists.

  4. #4
    Join Date
    Jun 2009
    Location
    Bato, Leyte, Philippines
    Posts
    10
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Bring application window to front

    Try this, it works....

    this->setWindowFlags(Qt::WindowStaysOnTopHint);


    Tell me if your problem still not solved....

  5. #5
    Join Date
    Jun 2009
    Posts
    10

    Default Re: Bring application window to front

    No Does not work.. I've tried setFocus() (with setFocusPolicy), QAppilcation::setActiveWindow(), activateWindow(), show(), but they have all no effect.

    Only flashing on taskbar (((

    I've tried SetWindowPos with HWND_TOPMOST flag. It brings window to top. But in this case there were a problem, that window became "always on top" FOREVER. I' could not remove this attribute. If i passed HWND_NOTOPMOST, window jumped to bottom.. under another opened window. But i need it stays only visually on top, and can be overlapped by other windows.

    PS: There were no "always on top" windows on desktop.

  6. #6
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Bring application window to front

    you said that the message is sent from another application? so are the two applications Qt applications? If yes then take a look at QtSingleApplication class (its a solution from troll). what they have done is that they send message to other application which is caught in some function(slot may be).

    so the point is that somehow you land up in your application's function.. in that.. you can experiment with first setting the windowOnTop flast and then reseting. ..

    i dont remeber QtSingleApplication code so this info may not be correct.

  7. #7
    Join Date
    Jun 2009
    Posts
    10

    Default Re: Bring application window to front

    To Mr.Death: Yes. It was exactly what i need. Thank you. You were right, i have 2 Qt applications. I'll try to use this, but i am not sure, that QtSingleApplication solution is included in version 4.5.1, that used by company i am working in. But i'll try. thanks.
    PS: Another suggestions will be investigated too..

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Bring application window to front

    You can always use the SendMessage() WinAPI call to deliver a custom message to another application and then you can catch that message there and use raise() and setActiveWindow() (or whatever other combination you find useful).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jun 2009
    Posts
    10

    Default Re: Bring application window to front

    I have exactly such implementation with SendMessage() as you say.
    But raise() and activateWindow() and many others WinAPI calls did not worked!

    Yesterday, i have found the problem.
    It used AllowSetForegroundWindow() call which made the raise() call work. I think it was because raise() is implemented through SetForegroundWindow() API.

    Thanks to all.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Bring application window to front

    Quote Originally Posted by St@n View Post
    I have exactly such implementation with SendMessage() as you say.
    But raise() and activateWindow() and many others WinAPI calls did not worked!
    How exactly did you call them?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Jun 2009
    Posts
    10

    Default Re: Bring application window to front

    mainDialog->activateWindow()
    mainDialog->raise()

    PS: Problem is resolved

  12. #12
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Bring application window to front

    can u put some example code of how exactly u did it..?

  13. #13
    Join Date
    Jul 2010
    Location
    Ahmedabad,Gujarat,India
    Posts
    25
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Bring application window to front

    Try this it might be helps you.

    this->stackUnder(parentWidget()); [this means is your QMainWindow]

  14. #14
    Join Date
    Jul 2019
    Posts
    1
    Qt products
    Qt4 Qt5 PyQt3 PyQt4
    Platforms
    Unix/X11 Windows Android

    Default Re: Bring application window to front

    Quote Originally Posted by pavanbarot View Post
    Try this it might be helps you.

    this->stackUnder(parentWidget()); [this means is your QMainWindow]
    I used the following code to make a PyQt4 window the topmost window and to bring it to the front (in front of all other windows) in a Windows 10 64 bit environment:

    self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint )

    # The following is drawn from: https://stackoverflow.com/questions/...p-to-the-front
    # the following will remove minimized status
    # and restore window with keeping maximized/normal state
    self.setWindowState(self.windowState() & ~QtCore.Qt.WindowMinimized | QtCore.Qt.WindowActive)

    # this will activate the window
    self.activateWindow()

Similar Threads

  1. Replies: 11
    Last Post: 15th July 2008, 14:11
  2. Qt3 Bring to front application
    By nleverin in forum Qt Programming
    Replies: 1
    Last Post: 7th February 2008, 12:27
  3. Independant window in an application
    By titoo in forum Qt Programming
    Replies: 4
    Last Post: 28th February 2007, 12:07
  4. move parent window to the front.
    By hvengel in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2007, 09:41
  5. Replies: 0
    Last Post: 21st February 2006, 17:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.