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)

https://www.youtube.com/watch?v=cuEljQAlWds

Any help would be appreciated
Thanks

Helper class:

Qt Code:
  1. #define WINVER 0x0A00
  2. #define _WIN32_WINNT 0x0A00
  3.  
  4.  
  5. #ifndef DWMWA_SYSTEMBACKDROP_TYPE
  6. #define DWMWA_SYSTEMBACKDROP_TYPE 38
  7. #endif
  8.  
  9. #include "micahelper.h"
  10. #include <qt_windows.h>
  11. #include <dwmapi.h>
  12. #include <QDebug>
  13. #include <QColor>
  14.  
  15. // Define the DWM_SYSTEMBACKDROP_TYPE enum
  16. enum DWM_SYSTEMBACKDROP_TYPE
  17. {
  18. DWMSBT_AUTO,
  19. DWMSBT_NONE,
  20. DWMSBT_MAINWINDOW,
  21. DWMSBT_TRANSIENTWINDOW,
  22. DWMSBT_TABBEDWINDOW,
  23. };
  24.  
  25. void MicaHelper::enableMicaForWindow(QWindow *window)
  26. {
  27. if (!window) {
  28. qDebug() << "Error in MicaHelper: Window object is null.";
  29. return;
  30. }
  31.  
  32.  
  33.  
  34.  
  35. #ifdef Q_OS_WIN
  36. HWND hwnd = reinterpret_cast<HWND>(window->winId());
  37.  
  38. if (hwnd) {
  39. DWM_SYSTEMBACKDROP_TYPE backdropType = DWMSBT_MAINWINDOW;
  40.  
  41. HRESULT hr = DwmSetWindowAttribute(
  42. hwnd,
  43. DWMWA_SYSTEMBACKDROP_TYPE,
  44. &backdropType,
  45. sizeof(backdropType)
  46. );
  47.  
  48. if (FAILED(hr)) {
  49. qDebug() << "Failed to set Mica effect via DWM. HRESULT:" << hr;
  50. } else {
  51. qDebug() << "Mica effect applied successfully. HWND value:" << (qintptr)hwnd;
  52. }
  53. } else {
  54. qDebug() << "Error in MicaHelper: HWND is 0x0.";
  55. }
  56. #else
  57. Q_UNUSED(window);
  58. qDebug() << "Mica effect is only supported on Windows.";
  59. #endif
  60. }
To copy to clipboard, switch view to plain text mode 



main.cpp:

Qt Code:
  1. #include <QGuiApplication>
  2. #include <QQmlApplicationEngine>
  3. #include <QQuickWindow>
  4.  
  5. #include <Windows.h>
  6. #include <dwmapi.h>
  7. #include "micahelper.h"
  8. #include <QQmlContext>
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12. // QQuickWindow::setDefaultAlphaBuffer(true);
  13. QGuiApplication app(argc, argv);
  14.  
  15. QQmlApplicationEngine engine;
  16.  
  17. MicaHelper micaHelper;
  18. engine.rootContext()->setContextProperty("micaHelper", &micaHelper); // Expose the C++ object to QML
  19.  
  20.  
  21.  
  22. QObject::connect(
  23. &engine,
  24. &QQmlApplicationEngine::objectCreationFailed,
  25. &app,
  26. []() { QCoreApplication::exit(-1); },
  27. Qt::QueuedConnection);
  28. engine.loadFromModule("sRadioWindowsQt6", "Main");
  29.  
  30. return app.exec();
  31. }
To copy to clipboard, switch view to plain text mode 


main.qml

Qt Code:
  1. main.qml
To copy to clipboard, switch view to plain text mode