Using Qt5 and possibly KWindowSystem may solve the problem.
In the KDE Plasma desktop environment, the window manager KWin is responsible for handling and managing windows. When you right-click on a window title bar and select "Keep Above Others", KWin receives a command to make that window stay on top. This is an internal implementation in KWin, and is independent of Qt and QWidget. KWin sets that window to be always on top and adjusts the window stacking order accordingly.
KWin provides interfaces to interact with other KDE applications and libraries, such as the aforementioned KWindowSystem. Through these interfaces, you can programmatically interact with KWin, such as setting a window to stay on top.
However, on Wayland, KWin does not provide a D-Bus interface for this functionality. This is why on Wayland, we need to use KWindowSystem, as it abstracts the interaction with the window manager and provides a unified API for both X11 and Wayland. On Wayland, KWindowSystem uses other ways to communicate with KWin instead of D-Bus.
Therefore, to summarize, in the KDE Plasma desktop environment, KWin is responsible for the "Keep Above Others" functionality. In programming, we can use KWindowSystem (as a higher-level abstraction) to set a window to stay on top. This ensures compatibility between different window managers and display servers.