Skip to content

Avoid native window recreation when toggling stay-on-top #254

Closed

Description

@hesphoros

Problem

A typical Qt Widgets stay-on-top implementation changes Qt::WindowStaysOnTopHint and calls show() again:

window->setWindowFlag(Qt::WindowStaysOnTopHint, pinned);
window->show();

We have observed native window recreation on both Windows and macOS when toggling this flag. The hide/show and recreation cause visible flicker and require native window state to be rebound. On Windows, recreation can also cause frame position drift. Linux has not been verified.

#241 explored changing the Win32 topmost state directly in the example. The merged #243 fixes frame drift after an HWND recreation. An in-place stay-on-top operation would avoid recreation when only the stacking level needs to change.

Proposal

Could QWindowKit provide an explicit stay-on-top operation for managed windows, either as a window-agent method or a documented window attribute?

  • Windows: update the existing HWND using SetWindowPos() with HWND_TOPMOST / HWND_NOTOPMOST.
  • macOS: update the existing NSWindow level.
  • Linux: investigate backend behavior before defining support or fallback semantics.

The requested state should be restored if the native window is recreated for another reason. The API should document that a native stacking change may not update Qt's windowFlags().

Expected behavior

On supported backends, repeatedly toggling stay-on-top should preserve window visibility, frame geometry, and native window identity without flicker.

Activity

  1. hesphoros commented on Oct 17, 2026

    @hesphoros
    ContributorAuthor
  2. wangwenx190 commented on Oct 19, 2026

    @wangwenx190
    Collaborator

    我也不知道为什么Qt这边改window flag总要重新创建窗口,而且还总会把窗口隐藏,还要手动再显示出来。但就像你说的,如果我们手动改window style,绕过qt,那么window flags就会和qt那边不同步,不知道会不会引入什么隐患。这个接口倒是可以加的,代码也很简单。我和另一个维护者再商量下看看

  3. self-assigned this
    on Oct 19, 2026
  4. added
    bugSomething isn't working
    and removed
    bugSomething isn't working
    on Oct 19, 2026
  5. wangwenx190 commented on Oct 19, 2026

    @wangwenx190
    Collaborator

    我们商量了一下,感觉与qt失去同步这个风险有点高,而且qt窗口在修改window flag时会闪一下是qt多少年以来就存在的问题,我们决定还是暂时不引入这种改动。如果你真的非常在意这个问题的话,可以自己维护一个fork,使用你自己修改的版本

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

wontfixThis will not be worked on

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions