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

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 *

This site uses Akismet to reduce spam. Learn how your comment data is processed.