Phantom white box whilst using Application Window and Windows 11 Mica background on QML, qt 6.10.1
-
Hi everyone,
I've been experimenting with applying a Windows 11 Mica background effect to a QML Application using Windows 11 24H2 with Qt 6.10.1.The mica effect works, but there's a white box in the Application Window, it seems to be to be related to the initial window width and height as when i resize the window it doesn't increase and the mica background behind it shows as it should (see Video it will explain what I mean)
Any help would be appreciated:)
ThanksHelper class:
// Source - https://stackoverflow.com/q/79846711 // Posted by Paul, modified by community. See post 'Timeline' for change history // Retrieved 2025-12-14, License - CC BY-SA 4.0 #define WINVER 0x0A00 #define _WIN32_WINNT 0x0A00 #ifndef DWMWA_SYSTEMBACKDROP_TYPE #define DWMWA_SYSTEMBACKDROP_TYPE 38 #endif #include "micahelper.h" #include <qt_windows.h> #include <dwmapi.h> #include <QDebug> #include <QColor> // Define the DWM_SYSTEMBACKDROP_TYPE enum enum DWM_SYSTEMBACKDROP_TYPE { DWMSBT_AUTO, DWMSBT_NONE, DWMSBT_MAINWINDOW, DWMSBT_TRANSIENTWINDOW, DWMSBT_TABBEDWINDOW, }; void MicaHelper::enableMicaForWindow(QWindow *window) { if (!window) { qDebug() << "Error in MicaHelper: Window object is null."; return; } #ifdef Q_OS_WIN HWND hwnd = reinterpret_cast<HWND>(window->winId()); if (hwnd) { DWM_SYSTEMBACKDROP_TYPE backdropType = DWMSBT_MAINWINDOW; HRESULT hr = DwmSetWindowAttribute( hwnd, DWMWA_SYSTEMBACKDROP_TYPE, &backdropType, sizeof(backdropType) ); if (FAILED(hr)) { qDebug() << "Failed to set Mica effect via DWM. HRESULT:" << hr; } else { qDebug() << "Mica effect applied successfully. HWND value:" << (qintptr)hwnd; } } else { qDebug() << "Error in MicaHelper: HWND is 0x0."; } #else Q_UNUSED(window); qDebug() << "Mica effect is only supported on Windows."; #endif }main.cpp:
// Source - https://stackoverflow.com/q/79846711 // Posted by Paul, modified by community. See post 'Timeline' for change history // Retrieved 2025-12-14, License - CC BY-SA 4.0 #include <QGuiApplication> #include <QQmlApplicationEngine> #include <QQuickWindow> #include <Windows.h> #include <dwmapi.h> #include "micahelper.h" #include <QQmlContext> int main(int argc, char *argv[]) { // QQuickWindow::setDefaultAlphaBuffer(true); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; MicaHelper micaHelper; engine.rootContext()->setContextProperty("micaHelper", &micaHelper); // Expose the C++ object to QML QObject::connect( &engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.loadFromModule("sRadioWindowsQt6", "Main"); return app.exec(); }main.qml
// Source - https://stackoverflow.com/q/79846711 // Posted by Paul, modified by community. See post 'Timeline' for change history // Retrieved 2025-12-14, License - CC BY-SA 4.0 import QtQuick import QtQuick.Window import QtQuick.Controls ApplicationWindow { // Swapped from Window to ApplicationWindow id: appWindow visible: true width: 640 height: 480 title: qsTr("Mica ApplicationWindow ") color: "transparent" // <--- MUST be transparent // Call the C++ function using the new C++ function signature Component.onCompleted: { console.log("QML: Component completed. Passing window object to C++."); // Pass the ApplicationWindow object itself micaHelper.enableMicaForWindow(appWindow); } // Header/Footer/Content area setup header: Rectangle { height: 50 color: "transparent" // Headers also need to be transparent to blend Label { text: "My Title Bar"; anchors.centerIn: parent } } // The contentItem is a default Item with no color, so Mica shows through it automatically // Your UI elements go inside here. Label { anchors.centerIn: parent text: "Mica Label" } } -
Small development, it seems that minimising the window then resizing will permanently remove the white box, could this be some kind of cache or graphics buffer which is cleared when the window is out of view?
Setting visible on the window doesn't fix the box
See video for new behaviour: