How can I create a frameless fixed size window compatible with high DPI?
-
I'm creating an application in a frameless fixed size window, which must support the Windows 10 per-monitor high DPI features, and be visible in the taskbar and behaves as any other normal Windows application. I also needed to implement my own form header instead of the default system one.
However I'm in trouble with the high DPI behavior, which isn't working as I expect. What I need is a form which keeps the same proportions on the different DPI and monitors, but keeping its visual size unchanged.
However what I get is a completely buggy high DPI behavior, which I described in the unfortunately never answered following thread: https://forum.qt.io/topic/122389/some-trouble-with-high-dpi
I tried to play around the following configuration:
ApplicationWindow { // common properties id: awMainForm width: 602 height: 728 minimumWidth: 602 minimumHeight: 728 maximumWidth: 602 maximumHeight: 728 flags: Qt.FramelessWindowHint | Qt.Window visible: true // form content isn't relevant ... }
I'm aware that the error comes from the way I configured my form rather than a bug in Qt. The issue seems to come from the window flags, in association with the non-sizeable constraint. For example, if I remove the Qt.Window flag, all works fine with the high DPI, but several other side effects appear, e.g I can no longer find my window onto the taskbar, nor restore it after a minimize.
NOTE as I said above, I implemented my own form header, it's the reason why I still can move my window despite of removing the Qt.Window flag.
So, what is the correct way to create a frameless fixed size window which can be minimized and visible onto the taskbar and supports correctly the Windows 10 per-monitor high DPI feature? How should I configure my window to reach a such behavior, or which functions/messages should I override to reach that?
-
I finally found a solution which seems to work in my case. I added the
Qt.MSWindowsFixedSizeDialogHint
window flag, which seems to fix the issue.So below is the modified code:
ApplicationWindow { // common properties id: awMainForm width: 602 height: 728 flags: Qt.Window | Qt.FramelessWindowHint | Qt.MSWindowsFixedSizeDialogHint visible: true // form content isn't relevant ... }
-
@jeanmilost Have you had a look at this project
https://github.com/wangwenx190/framelesshelperWhich has
Features Support Windows, X11, Wayland and macOS. Frameless but have frame shadow. Draggable and resizable. Automatically high DPI scaling. Multi-monitor support (different resolution and DPI). Have animations when minimizing, maximizing and restoring. Support tiled and stack windows by DWM (Win32 only). Won't cover the task bar when maximized (Win32 only). Won't block the auto-hide task bar when maximized (Win32 only). No flickers when resizing. Load all native APIs at run-time, no need to link to any system libraries directly (Win32 only).
-
I finally found a solution which seems to work in my case. I added the
Qt.MSWindowsFixedSizeDialogHint
window flag, which seems to fix the issue.So below is the modified code:
ApplicationWindow { // common properties id: awMainForm width: 602 height: 728 flags: Qt.Window | Qt.FramelessWindowHint | Qt.MSWindowsFixedSizeDialogHint visible: true // form content isn't relevant ... }