Fluent-Qt

QmlBridge

QmlView

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

Example

QmlView: Load a QML page

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();
}

fluent::qmlbridge::QmlView

Inherits QWidget · FluentElement · QMLPlus

Hosts an application QML page inside a caller-owned QWidget.

Constructors

Properties

QUrl source
Read source()Notify sourceChanged()
Status status
Read status()Notify statusChanged()
bool active
Read isActive()Notify activeChanged()
QStringList errors
Read errors()Notify errorsChanged()
QString lastError
Read lastError()Notify errorsChanged()
QObject* theme

Returns the view-owned fluentTheme object.

Read themeObject()
bool textureRenderingEnabled

Returns the requested texture presentation mode.

Read isTextureRenderingEnabled()Write setTextureRenderingEnabled()Notify textureRenderingEnabledChanged()

Methods

QObject* rootObject() const

Returns the borrowed QML root, invalidated by unload or replacement.

QObject* themeObject() const

Returns 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() const

Returns 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() const

Returns a borrowed premultiplied RGBA, bottom-up GL texture or zero. Invalidated by release, unload, resize or context replacement.

QSize textureSize() const

Returns the texture dimensions in device pixels.

quint64 textureRevision() const

Returns the monotonically increasing revision of rendered content.

QVariantMap textureStatistics() const

Returns 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 Status
  • Unloaded
  • Loading
  • Ready
  • Error

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() const

Resolves the theme used by this element, honoring an inherited QWidget override.

bool effectiveThemeUsesDarkAppearance() const

Returns whether this element's effective theme uses dark-backed chrome.

QJsonObject themeOverrides() const

Returns this element's authored overrides.

void clearThemeOverrides()

Restores all token fields to global theme defaults.

const Colors& themeColorsRef() const

Non-copying access to the active color set (for hot paint paths).

Material::AcrylicToken themeAcrylic() const

Material, elevation, and adaptive layout tokens.

QColor themeBackdrop(bool active) const

Window-chrome backdrop color for the given activation state.

virtual void onThemeUpdated()

Called after the global theme changes.

Enumerations

enum Theme

Global visual theme used when resolving design tokens.

  • Light = 0
  • Dark = 1
  • HighContrast = 2

Types and aliases

struct Colors

Design 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 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