<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Drawing error when using Qt6.6.1 using windows native event WM_NCCALCSIZE]]></title><description><![CDATA[<p dir="auto">I try to draw FramelessWindow using Qt6.6.1 with this method:</p>
<ul>
<li>set <code>FramelessWindowHint</code></li>
<li>using windows api <code>SetWindowLong</code> set <code>WS_THICKFRAME</code>  style</li>
<li>using <code>WM_NCCALCSIZE</code> message to cover title bar<br />
it is completely correct when window is not maximized.<br />
However, when maximizing, the right and bottom sides will exceed the drawable range.</li>
</ul>
<p dir="auto">But in old Qt version like 6.3.2 has no problem, it seems to have occurred after 6.4.2, and also can be reproduced in PyQt.<br />
This is the effect in Qt6.3.2<br />
<img src="https://ddgobkiprc33d.cloudfront.net/d7d33886-0436-4e8d-a132-9a5fe83a02d7.png" alt="ZxctG.png" class=" img-fluid img-markdown" /><br />
and the result in Qt6.6.1<br />
<img src="https://ddgobkiprc33d.cloudfront.net/4d0fc715-22d3-41c4-b70a-cda0fa51da4d.png" alt="VzdCN.png" class=" img-fluid img-markdown" /><br />
It can be observed that the third button exceeds the boundary.<br />
Is there any way to get same result in Qt6.6.1<br />
The full test code like:</p>
<pre><code class="language-cpp">#include "mainwindow.h"
#include &lt;QGuiApplication&gt;
#include &lt;QWindow&gt;
#include "ui_mainwindow.h"
#include &lt;Windows.h&gt;
#include &lt;dwmapi.h&gt;

#pragma comment(lib, "user32.lib")
#pragma comment(lib, "dwmapi.lib")

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui-&gt;setupUi(this);
    this-&gt;setWindowFlags(this-&gt;windowFlags() | Qt::FramelessWindowHint);
    auto style = GetWindowLong((HWND) this-&gt;winId(), GWL_STYLE);
    SetWindowLong((HWND) this-&gt;winId(),
                  GWL_STYLE,
                  style | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_CAPTION | CS_DBLCLKS | WS_THICKFRAME
                      | WS_OVERLAPPED);
    SetWindowPos((HWND) this-&gt;winId(),
                 HWND_TOP,
                 0,
                 0,
                 0,
                 0,
                 SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED);
    this-&gt;showMaximized();
}

MainWindow::~MainWindow()
{
    delete ui;
}

bool isMaximized(HWND hWnd)
{
    WINDOWPLACEMENT windowPlacement;
    windowPlacement.length = sizeof(WINDOWPLACEMENT);
    bool ret = GetWindowPlacement(hWnd, &amp;windowPlacement);
    if (!ret) {
        return false;
    }

    return windowPlacement.showCmd == SW_MAXIMIZE;
}

QWindow *findWindow(HWND hWnd)
{
    if (!hWnd)
        return nullptr;
    auto windows = QGuiApplication::topLevelWindows();
    if (windows.size() == 0)
        return nullptr;
    int id = int(hWnd);
    foreach (auto w, windows) {
        if (int(w-&gt;winId()) == id) {
            return w;
        }
    }
    return nullptr;
}

int getResizeBorderThickness(HWND hWnd, bool hor = true)
{
    auto window = findWindow(hWnd);
    if (!window) {
        return 0;
    }
    auto frame = hor ? SM_CXSIZEFRAME : SM_CYSIZEFRAME;
    auto size = GetSystemMetrics(frame) + GetSystemMetrics(92);
    if (size &gt; 0)
        return size;
    int res = 0;
    DwmIsCompositionEnabled(&amp;res);
    auto thickness = res ? 8 : 4;
    return int(thickness * window-&gt;devicePixelRatio());
}

bool MainWindow::nativeEvent(const QByteArray &amp;eventType, void *message, qintptr *result)
{
    if (eventType != "windows_generic_MSG") {
        return false;
    }
    MSG *msg = (MSG *) message;
    if (msg-&gt;hwnd == nullptr)
        return false;
    switch (msg-&gt;message) {
    case WM_NCCALCSIZE: {
        auto isMax = ::isMaximized(msg-&gt;hwnd);
        auto setRectMax = [](HWND hWnd, LPRECT rect) {
            int tx = getResizeBorderThickness(hWnd);
            int ty = getResizeBorderThickness(hWnd, false);
            rect-&gt;top += ty;
            rect-&gt;bottom -= ty;
            rect-&gt;left += tx;
            rect-&gt;right -= tx;
        };
        if (msg-&gt;wParam) {
            LPNCCALCSIZE_PARAMS rect = (LPNCCALCSIZE_PARAMS) (msg-&gt;lParam);
            if (isMax) {
                setRectMax(msg-&gt;hwnd, rect-&gt;rgrc);
            }
        } else {
            LPRECT rect = (LPRECT) (msg-&gt;lParam);
            if (isMax) {
                setRectMax(msg-&gt;hwnd, rect);
            }
        }
        *result = msg-&gt;wParam ? 0 : WVR_REDRAW;
        return true;
    }
    }
    return false;
}
</code></pre>
]]></description><link>https://forum.qt.io/topic/153086/drawing-error-when-using-qt6-6-1-using-windows-native-event-wm_nccalcsize</link><generator>RSS for Node</generator><lastBuildDate>Tue, 08 Sep 2026 01:00:15 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/153086.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 17 Dec 2023 03:24:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Drawing error when using Qt6.6.1 using windows native event WM_NCCALCSIZE on Thu, 21 Dec 2023 14:54:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alexzhzz">@<bdi>AlexZhZZ</bdi></a><br />
See <a href="https://bugreports.qt.io/browse/QTBUG-120196" target="_blank" rel="noopener noreferrer nofollow ugc">QTBUG-120196</a></p>
]]></description><link>https://forum.qt.io/post/783888</link><guid isPermaLink="true">https://forum.qt.io/post/783888</guid><dc:creator><![CDATA[AlexZhZZ]]></dc:creator><pubDate>Thu, 21 Dec 2023 14:54:29 GMT</pubDate></item><item><title><![CDATA[Reply to Drawing error when using Qt6.6.1 using windows native event WM_NCCALCSIZE on Sun, 17 Dec 2023 03:34:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/alexzhzz">@<bdi>AlexZhZZ</bdi></a><br />
Also, if the implementation of WM_NCCALCSIZE is removed, and the title bar is no longer overridden, it can be observed that the window drawing is also incorrect in the non-maximized state.<br />
This seems to happen when both <code>FramelessWindowHint</code> and <code>SetWindowLong</code> are used simultaneously, even if only the style obtained through <code>GetWindowLong</code> is set.<br />
<img src="https://ddgobkiprc33d.cloudfront.net/d5b73498-b034-48bd-ab31-af4c9fb98f70.png" alt="Qt6.6.1" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/783503</link><guid isPermaLink="true">https://forum.qt.io/post/783503</guid><dc:creator><![CDATA[AlexZhZZ]]></dc:creator><pubDate>Sun, 17 Dec 2023 03:34:48 GMT</pubDate></item></channel></rss>