chaomi1998
chaomi1998

Reputation: 11

Unexpected rounded corners in Qt Frameless Widget

Unexpected rounded corners in Qt Frameless Widget I use Qt and Windows API to create a window with a custom title bar, and I want this window to have some of the effects of a Windows window (maximize, minimize, close, etc.). When I added the WS_CAPTION attribute to make my window have these effects, the title bar had rounded corners that were not what I expected. I am developing on the Windows 10 platform and I am certain that this rounded corner is not related to Windows 11.

This is code without window effect:

FramelessDialog::FramelessDialog(QWidget* parent)
    : QDialog{parent} {
    setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint);
    setAttribute(Qt::WA_TranslucentBackground);
#ifdef Q_OS_WIN
    HWND hwnd = (HWND)this->winId();
    DWORD style = ::GetWindowLongPtr(hwnd, GWL_STYLE);
    ::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX);
#endif
}

and it screenshot:

enter image description here

This is the code with those effects:

FramelessDialog::FramelessDialog(QWidget* parent)
    : QDialog{parent} {
    setWindowFlags(windowFlags() | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint);
    setAttribute(Qt::WA_TranslucentBackground);
#ifdef Q_OS_WIN
    HWND hwnd = (HWND)this->winId();
    DWORD style = ::GetWindowLongPtr(hwnd, GWL_STYLE);
    ::SetWindowLongPtr(hwnd, GWL_STYLE, style | WS_THICKFRAME | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX | WS_CAPTION);
#endif
}

and it screenshot:

enter image description here

Strange rounded corners appear on the top left and top right, why is this happening, and what should I do to close it.

Upvotes: 0

Views: 84

Answers (0)

Related Questions