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 application to front - portable way
Forum Update on Monday, May 27th 2025

Bring application to front - portable way

Scheduled Pinned Locked Moved Unsolved General and Desktop
topmostbring to frontportable
1 Posts 1 Posters 1.3k Views
  • 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.
  • R Offline
    R Offline
    Radek
    wrote on 20 Sept 2016, 07:13 last edited by Radek
    #1

    Hello forum!

    First of all, here's my setup: Windows 7 - 64bits, Qt 5.2.0. (MSVC 2010, 32 bit), Qtcreator 3.0.0. Developped application based on QMainWindow.

    I'm currently trying to figure out a Qt (portable) way of bringign my application back to front, when it receives a defined tcp message.(The tcp stuff works perfectly - yay!)
    I know there are a few topics and answers around the internet and on QtForum, like this one:
    Re: Bring window to front -> raise()
    ... but they're all old, and not working in my case.

    I've tried lots of things and combinations of raise(), activatewindow(), setWindowFlags(), show() and whatnot.
    The only thing that partially worked was

    setWindowFlags(windowFlags() ^ Qt::WindowStaysOnTopHint);
    show();
    setWindowFlags(windowFlags() & ~Qt::WindowStaysOnTopHint);
    show();
    

    or other ways of writing it but I hit a problem with that because the window stays on top, as if you couldn't remove
    the Qt::WindowStaysOnTopHint flag.

    So the workaround I found was call native Win32 API:

        SetWindowPos((HWND)winId(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
        SetWindowPos((HWND)winId(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
    

    Then it works, my app is back to front, but not locked to front!
    Kinda hacky you say? ... yes, and I dont't like it bc it's not portable.

    Anyone would have a Qt solution?
    Thx for your time and neurons.

    There is no problem, there are only solutions. :)

    1 Reply Last reply
    0

    1/1

    20 Sept 2016, 07:13

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved