Embed QML (QmlBridge)
QmlView
A QML surface that shares application models and Fluent theme tokens with the surrounding Widgets.
Example
Property preview could not load. Select Property preview to retry.

Usage
Load a QML page
Activate a QmlSession, create a QmlView with QmlSession::createView(), and load a QML URL. When sharing a window with OpenGL views, select the Quick graphics backend before creating the first Quick view.
#include <FluentQt/QmlBridge.h>
using namespace fluent::qmlbridge;
// main.cpp; build with CMakeLists.txt and keep the QML page in its own file.
#include <FluentQt/FluentQt.h>
#include <FluentQt/QmlBridge.h>
#include <QApplication>
#include <QHBoxLayout>
#include <QVBoxLayout>
using fluent::basicinput::Button;
using fluent::qmlbridge::QmlSession;
using fluent::qmlbridge::QmlView;
using fluent::status_info::ProgressBar;
using fluent::textfields::Label;
using fluent::textfields::LineEdit;
using fluent::windowing::Window;
QWidget* makePanel(const QUrl& source, QWidget* parent)
{
auto* panel = new QWidget(parent);
auto* column = new QVBoxLayout(panel);
column->setContentsMargins(16, 16, 16, 16);
column->setSpacing(12);
column->setAlignment(Qt::AlignTop);
auto* session = new QmlSession(panel, panel);
QString error;
QmlView* view = session->activate(&error) ? session->createView(panel) : nullptr;
if (!view) {
column->addWidget(new Label(error.isEmpty() ? "QML is unavailable" : error, panel));
return panel;
}
view->setFixedHeight(100);
column->addWidget(view);
view->load(source);
return panel;
}
int main(int argc, char* argv[])
{
fluent::prepareHighDpiApplication();
QmlSession::prepareApplication();
QApplication application(argc, argv);
fluent::initializeResources();
application.setFont(Typography::fontStyle(Typography::FontRole::Body).toQFont());
Window window;
window.setWindowTitle("QmlView");
window.resize(640, 480);
window.setContentWidget(makePanel(QUrl("qrc:/Basic.qml"), &window));
window.show();
return application.exec();
}import fluentqt
from fluentqt.qmlbridge import QmlSession
# main() calls QmlSession.prepareApplication() before QApplication.
# panel and qml_source() are defined in Full example.
session = QmlSession(panel, panel)
view = session.createView(panel) if session.activate() else None
if view is not None:
view.setFixedHeight(100)
view.load(qml_source("Basic"))API
DeclarationNo matching API members.
fluent::qmlbridge::QmlView
Inherits QWidget · FluentElement · QMLPlus
QWidget container for embedding and displaying an application QML page. Attach to an active QmlSession before use; load only trusted QML (scenes unload automatically when the session deactivates).
Constructors
Properties
QUrl source- Read
source()NotifysourceChanged() Status status- Read
status()NotifystatusChanged() bool active- Read
isActive()NotifyactiveChanged() QStringList errors- Read
errors()NotifyerrorsChanged() QString lastError- Read
lastError()NotifyerrorsChanged() QObject* themeReturns the view-owned fluentTheme context object.
ReadthemeObject()bool textureRenderingEnabledWhether offscreen texture rendering is enabled.
ReadisTextureRenderingEnabled()WritesetTextureRenderingEnabled()NotifytextureRenderingEnabledChanged()
Methods
QObject* rootObject() constReturns the loaded QML root object, or nullptr until ready or after unload().
QObject* themeObject() constReturns the view-owned fluentTheme context object.
bool setContextObject(const QString& name, QObject* object)Registers a GUI-thread QObject under name before loading (pass nullptr to remove; "fluentTheme" is reserved). Caller retains object lifetime; bindings persist across unload() and destroying a bound object unloads the scene.
bool load(const QUrl& source, QString* error = nullptr)Loads an absolute QML URL; returns true when ready or async loading starts. Watch statusChanged() and errorOccurred() for async errors; call unload() first to reload the same URL.
void unload()Unloads the QML scene and resets status while keeping external context bindings intact. Safe to call from QML callbacks (teardown is deferred until callbacks unwind).
bool setTextureRenderingEnabled(bool enabled)Toggles offscreen OpenGL texture rendering without reloading the QML scene. When enabled, the caller must invoke renderTexture() and draw the texture; may be set before load().
bool isTextureRenderingEnabled() constWhether offscreen texture rendering is enabled.
bool renderTexture(QOpenGLContext* context, qreal devicePixelRatio, quint64 maximumBytes = 67108864)Renders the QML scene into a texture using the caller's current OpenGL context (GUI thread only). devicePixelRatio must be in (0, 4]; maximumBytes caps color/depth buffers.
unsigned int textureId() constReturns the premultiplied RGBA OpenGL texture (bottom-left origin), or 0 if unavailable. Invalidated on releaseTexture(), unload(), resize, or context change.
QSize textureSize() constTexture dimensions in device pixels.
quint64 textureRevision() constFrame revision counter incremented on each rendered frame.
QVariantMap textureStatistics() constDiagnostics map with texture memory usage, frame count, and last error.
void releaseTexture()Frees GPU render targets while keeping the QML scene and texture-mode setting intact.
Signals
void textureRenderingEnabledChanged(bool enabled)Whether offscreen texture rendering is enabled.
Enumerations
enum StatusUnloadedLoadingReadyError
Destructors
Protected members
Methods
Inherited from fluent::FluentElement
Methods
static void setTheme(Theme theme)Updates the global theme and notifies active FluentElement instances.
static void setThemeDeferred(Theme theme)Schedules a visible-first batched theme refresh without blocking the current interaction.
static Theme currentTheme()Returns the currently active global theme.
static bool themeUsesDarkAppearance(Theme theme)Returns whether a theme uses dark-backed chrome and material tokens.
static void refreshTheme()Re-broadcasts the current theme to repaint after a design-token change.
static int themeGeneration()Monotonic counter bumped on every theme change, for staleness checks.
Theme effectiveTheme() constResolves the theme used by this element, honoring an inherited QWidget override.
bool effectiveThemeUsesDarkAppearance() constReturns whether this element's effective theme uses dark-backed chrome.
bool setThemeOverrides(const QJsonObject& overrides)Replaces this element's sparse color, radius, and font token overrides.
QJsonObject themeOverrides() constReturns this element's authored overrides.
void clearThemeOverrides()Restores all token fields to global theme defaults.
const Colors& themeColorsRef() constNon-copying access to the active color set for hot paint paths.
Material::AcrylicToken themeAcrylic() constMaterial, elevation, and adaptive layout tokens.
QColor themeBackdrop(bool active) constWindow-chrome backdrop color for the given activation state.
virtual void onThemeUpdated()Called after the global theme changes.
Enumerations
enum ThemeGlobal visual theme used when resolving design tokens.
Light = 0Dark = 1HighContrast = 2
Types and aliases
struct ColorsDesign token snapshots returned to components.
Inherited from fluent::QMLPlus
Methods
AnchorLayout::Anchors* anchors()Returns mutable anchors for the QWidget host.
void setState(const QString& name)Applies a registered state by name, or restores the default state when @p name is empty. Unknown names are ignored, and existing bindings resume when leaving the state.
void addState(const QMLState& state)Registers or replaces a named state definition; replacing the active state applies it immediately.
void evaluateStates()Reevaluates state conditions in registration order and activates the first match, or the default state if none match. Also runs automatically when dependency properties notify; derived states using extend inherit ancestor changes unless cyclic or missing.
QMLPlusRuntime* runtime()Returns the lazily created state observer owned by this host.
void setAnchors(const AnchorLayout::Anchors& anchors)Replaces all host anchors and invalidates the parent layout.
void resetAnchors()Clears all host anchors and invalidates the parent layout.
void bind(const char* targetProp, QObject* source, const char* sourceProp, PropertyBinder::Direction dir = PropertyBinder::OneWay)Binds @p sourceProp on @p source to @p targetProp on this QWidget host via PropertyBinder::bind().
BindingHandle bindManaged(const char* targetProp, QObject* source, const char* sourceProp, PropertyBinder::Direction direction = PropertyBinder::OneWay, BindingOptions options = {})Installs a managed direct binding on this QWidget host.
BindingHandle bindComputed(const char* targetProp, const QVector<BindingDependency>& dependencies, std::function<QVariant()> evaluate, BindingOptions options = {})Installs an explicit-dependency C++ expression on this QWidget host.
void addTransition(const StateTransition& transition)Registers a state transition in precedence order.
void setBehavior(const char* propertyName, const PropertyAnimation& animation)Sets the default animation used when @p propertyName is written via writeProperty() or a binding. Explicit StateTransition rules take precedence; direct C++ setter calls are not animated.
void clearBehavior(const char* propertyName)Removes the default animation for future managed writes.
bool writeProperty(const char* propertyName, const QVariant& value)Writes a host property through Behavior without removing its binding.
Qt base class docs: QWidget