How WindowAgent works in Qt Quick (QML)
mainTo use QWindowKit in QML, you must first register the QWindowKit types in your C++ main.cpp and ensure the window supports transparency.
Setup Steps:
- In
main.cpp, callQQuickWindow::setDefaultAlphaBuffer(true)before creating any windows. This is required for transparency and platform effects like Mica or Acrylic. - Call
QWK::registerTypes(&engine)after creating yourQQmlApplicationEngine. - In QML, import
QWindowKit 1.0and use theWindowAgentcomponent.
Usage Pattern:
Inside a Component.onCompleted block in your QML file, initialize the agent:
WindowAgent {
id: windowAgent
}
Component.onCompleted: {
windowAgent.setup(window)
windowAgent.setTitleBar(titleBar)
windowAgent.setSystemButton(WindowAgent.Minimize, minButton)
windowAgent.setSystemButton(WindowAgent.Maximize, maxButton)
windowAgent.setSystemButton(WindowAgent.Close, closeButton)
}Interaction:
Just like in Widgets, if a control in the title bar (like a Button) needs mouse input, you must call windowAgent.setHitTestVisible(controlId, true) within Component.onCompleted or a similar lifecycle event.
// main.cpp setup
QQuickWindow::setDefaultAlphaBuffer(true);
QQmlApplicationEngine engine;
QWK::registerTypes(&engine);
// Main.qml usage
import QWindowKit 1.0
Window {
id: window
WindowAgent {
id: windowAgent
}
Rectangle {
id: titleBar
// ...
}
Component.onCompleted: {
windowAgent.setup(window)
windowAgent.setTitleBar(titleBar)
}
}