QmlBridge
QmlView
A QML surface that shares application models and Fluent theme tokens with the surrounding Widgets.
Example

Usage
Load a QML page
Create a QmlView and load one QML file.
#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
Hosts an application QML page inside a caller-owned QWidget.
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 object.
ReadthemeObject()bool textureRenderingEnabledReturns the requested texture presentation mode.
ReadisTextureRenderingEnabled()WritesetTextureRenderingEnabled()NotifytextureRenderingEnabledChanged()
Methods
QObject* rootObject() constReturns the borrowed QML root, invalidated by unload or replacement.
QObject* themeObject() constReturns the view-owned fluentTheme object.
bool setContextObject(const QString& name, QObject* object)Binds a borrowed GUI-thread QObject before loading; nullptr removes it.
bool load(const QUrl& source, QString* error = nullptr)Loads an absolute URL; true means ready or asynchronous loading accepted.
void unload()Detaches the QML scene and schedules its engine's safe destruction.
bool setTextureRenderingEnabled(bool enabled)Selects GPU texture presentation while retaining the same QML scene.
bool isTextureRenderingEnabled() constReturns the requested texture presentation mode.
bool renderTexture(QOpenGLContext* context, qreal devicePixelRatio, quint64 maximumBytes = 67108864)Renders or reuses the scene in the caller's current OpenGL context.
unsigned int textureId() constReturns a borrowed premultiplied RGBA, bottom-up GL texture or zero. Invalidated by release, unload, resize or context replacement.
QSize textureSize() constReturns the texture dimensions in device pixels.
quint64 textureRevision() constReturns the monotonically increasing revision of rendered content.
QVariantMap textureStatistics() constReturns GPU allocation, frame and failure diagnostics.
void releaseTexture()Releases GPU targets while retaining the scene and mode request.
Signals
void textureRenderingEnabledChanged(bool enabled)Returns the requested texture presentation mode.
Enumerations
enum StatusUnloadedLoadingReadyError
Destructors
Subclass interfaces
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)Component-facing token accessors.
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 named state, or clears state when name is empty.
void addState(const QMLState& state)Registers or replaces a named state definition.
void evaluateStates()Reevaluates conditions; the first registered true condition wins.
QMLPlusRuntime* runtime()Returns the lazy host-owned state observation object.
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 a source property to a property on the QWidget host.
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 for this host's managed property writes.
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.
All inherited Qt members:QWidget