How to make an application “Alway on Top” in C++ (For Qt and Win32)

Posted on Posted in Qt Tutorials, Tutorials

I use the following method to make an application remain on top of other windows in Qt:

SetWindowPos
(
(HWND)winId(),
HWND_TOPMOST,
window_top_pos,
window_left_pos,
window_width,
window_height,
SWP_SHOWWINDOW
);





Note that window_top_pos, window_left_pos, window_width and window_height are variables and you can replace them with your own.

Please be aware that this is a Win32 API function so it won’t work in Linux or MAC.

Don’t forget to add the include file to your code.

#include “windows.h”

And add the required library to your .PRO file.

LIBS += -luser32





Leave a Reply

Your email address will not be published. Required fields are marked *