English | 简体中文
A small Qt widget that outlines the window currently under the mouse cursor with a translucent frame — the "select a window" step of a screenshot tool, isolated into a runnable demo.
- Live window highlight — a frameless, always-on-top, translucent widget (
rgba(58,196,255,…)background with a 2 px border) that follows the window under the cursor. - Click-through on Windows — the overlay is set to
WA_TransparentForMouseEvents, so the desktop keeps receiving input; a low-level mouse hook (WH_MOUSE_LL) is installed instead to keep tracking mouse events. - Windows geometry —
WindowFromPoint()+GetWindowRect()are polled by a 200 msQTimerand applied withsetGeometry(). - X11 geometry — on Linux the root window's children are enumerated with
XQueryTree()/XGetWindowAttributes(), the visible window containing the cursor is picked (skipping the overlay itself) and applied withmove()+setFixedSize(). - Cross-platform build — one CMake project supporting Qt 5 and Qt 6 (
Widgetsonly), verified with Qt 5.15.2 + MSVC 2022 on Windows 10 22H2. - Reusable logic — the highlight goes through a hook plus
WindowFromPoint; the code notes its trade-offs, making it a reference to compare against custom window-filtering implementations.
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build --config ReleaseRequires CMake 3.5+ and Qt 5/6 with the Widgets module. Run the produced WindowRect executable and move the mouse across windows; the frame snaps to each window.
- GitHub: https://github.com/SunnyCapturer/WindowRect
- Window-enumeration experiment: https://github.com/SunnyCapturer/scroll
- Reference demo of the original technique: https://github.com/mahuifa/QMDemo