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:
#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
}
#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
}
To copy to clipboard, switch view to plain text mode
main.cpp:
#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
&engine,
&QQmlApplicationEngine::objectCreationFailed,
&app,
Qt::QueuedConnection);
engine.loadFromModule("sRadioWindowsQt6", "Main");
return app.exec();
}
#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();
}
To copy to clipboard, switch view to plain text mode
main.qml
main.qml
main.qml
To copy to clipboard, switch view to plain text mode
Bookmarks