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. QMainWindow windows always on top not working sometimes
Qt 6.11 is out! See what's new in the release blog

QMainWindow windows always on top not working sometimes

Scheduled Pinned Locked Moved General and Desktop
qmainwi
5 Posts 5 Posters 5.2k Views 3 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.
  • GiorgiG Offline
    GiorgiG Offline
    Giorgi
    wrote on last edited by Giorgi
    #1

    On windows 7 I have problem with window flag. I added this line in the constructor

    setWindowFlags(Qt::WindowStaysOnTopHint );
    

    when windows is going to render (after ctrl + r in qt creator) if suddenly i click on somewhere on text editor(qt creator text editor or in notepad if is open) this flag is not working correctly and rendered window stays on background. I found windows this solution:

    if(GetForegroundWindow() != reinterpret_cast<HWND>(winId())){
       qDebug() << "Here is my problem";
    }
    

    but now If I set again it doesn't working and window anyway stays background.

    setWindowFlags(Qt::WindowStaysOnTopHint );
    

    Can someone help me?

    D 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      @Giorgi said:

      setWindowFlags(Qt::WindowStaysOnTopHint );

      Works here on win 7, when set on the mainwindow. never falls behind anything.

      Have you tried with a new project and only
      setWindowFlags(Qt::WindowStaysOnTopHint );
      in constructor ?

      also ctrl +r is run app with no debug. Guess you can call it render :)

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Connie
        wrote on last edited by
        #3

        Hi,

        Have you found the solution to your problem? I am also having the same problem and am still cracking my head to solve this. If anyone has the solution, please post it here.

        kshegunovK 1 Reply Last reply
        0
        • C Connie

          Hi,

          Have you found the solution to your problem? I am also having the same problem and am still cracking my head to solve this. If anyone has the solution, please post it here.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @Connie
          Hello,
          Where are you setting the hint? Is it in the constructor? It has always worked for me, but there maybe some subtlety in your code.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0
          • GiorgiG Giorgi

            On windows 7 I have problem with window flag. I added this line in the constructor

            setWindowFlags(Qt::WindowStaysOnTopHint );
            

            when windows is going to render (after ctrl + r in qt creator) if suddenly i click on somewhere on text editor(qt creator text editor or in notepad if is open) this flag is not working correctly and rendered window stays on background. I found windows this solution:

            if(GetForegroundWindow() != reinterpret_cast<HWND>(winId())){
               qDebug() << "Here is my problem";
            }
            

            but now If I set again it doesn't working and window anyway stays background.

            setWindowFlags(Qt::WindowStaysOnTopHint );
            

            Can someone help me?

            D Offline
            D Offline
            Devopia53
            wrote on last edited by
            #5

            @Giorgi

            MSDN said: To use SetWindowPos to bring a window to the top, the process that owns the window must have SetForegroundWindow permission.

            eg.

            #include <Windows.h>

            SetForegroundWindow((HWND)winId());
            setWindowFlags(Qt::WindowStaysOnTopHint);

            // in .pro
            win32-g++:LIBS += libUser32
            win32-msvc*:LIBS += User32.lib

            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