Fluent-Qt

Spatial

SpatialView

Give existing widgets perspective and pointer tilt. Keep text editing and popups in the normal layout; native-window and OpenGL children cannot be embedded.

Example

SpatialView: Scene perspective

Usage

Scene perspective

Adjust the camera and zoom, then move the pointer over the cards.

#include <FluentQt/Spatial.h>
using namespace fluent::spatial;

using namespace fluent;
// The two cards keep their own poses while the view changes the whole scene.
class SceneView final : public spatial::SpatialView {
public:
    using SpatialView::SpatialView;
    void arrange()
    {
        if (itemCount() != 2)
            return;
        const float spread = width() < 650 ? 24 : 100;
        items().first()->setPosition(QVector3D(-spread, -44, -160));
        items().last()->setPosition(QVector3D(spread, 44, 160));
    }
protected:
    void resizeEvent(QResizeEvent* event) override
    {
        SpatialView::resizeEvent(event);
        arrange();
    }
};
auto* panel = new SpatialPreviewPanel(parent);
auto* column = new QVBoxLayout(panel);
column->setContentsMargins(0, 0, 0, 0);
column->setSpacing(16);
auto* session = new spatial::SpatialSession(panel, panel);
const bool active = session->activate();
auto* view = new SceneView(panel);
if (!active || !session->attachView(view)) {
    view->setSpatialEnabled(false);
    view->setRenderMode(spatial::SpatialView::RenderMode::Raster);
}
view->setObjectName("spatialPreviewView");
view->setFixedHeight(400);
view->setCameraDistance(1200);
view->setZoom(0.9);
view->setMaximumTilt(QPointF(6, 12));
// Response time (140 ms), animation limit (60 fps), cache and Auto renderer use UILib defaults.
// See SpatialView.h for the full parameter contract.

// Both layers use the same size and data, making perspective easy to compare.
const auto makeLayer = [](const QString& title, const QString& caption) {
    auto* card = new layout::Card;
    card->setFixedSize(220, 150);
    auto* content = new QVBoxLayout(card);
    content->setContentsMargins(16, 12, 16, 12);
    content->setSpacing(6);
    auto* heading = new textfields::Label(title, card);
    heading->setFluentTypography(Typography::FontRole::Subtitle);
    heading->setTextColorRole(textfields::Label::TextColorRole::Primary);
    content->addWidget(heading);
    auto* chart = new charts::Sparkline(card);
    chart->setAccessibleName(title + " sample chart");
    auto* model = new charts::ChartModel(card);
    model->setPoints({{0, 12}, {1, 24}, {2, 18}, {3, 38}, {4, 32}, {5, 54}});
    chart->setModel(model);
    content->addWidget(chart, 1);
    auto* note = new textfields::Label(caption, card);
    note->setTextColorRole(textfields::Label::TextColorRole::Secondary);
    content->addWidget(note);
    return card;
};
spatial::SpatialItem* back = view->addWidget(
    makeLayer("Back layer", "Z -160 · sample data"), WidgetOwnership::Owned);
spatial::SpatialItem* front = view->addWidget(
    makeLayer("Front layer", "Z +160 · sample data"), WidgetOwnership::Owned);
back->setRotation(QVector3D(6, 16, 0));
front->setRotation(QVector3D(-6, -16, 0));
back->setSurfaceIntensity(0.75);
front->setSurfaceIntensity(0.75);
view->arrange();

auto* toolbar = new QHBoxLayout;
auto* follow = new basicinput::ToggleSwitch(panel);
follow->setObjectName("spatialViewFollow");
follow->setAccessibleName("Follow pointer");
follow->setOnContent("Follow pointer");
follow->setOffContent("Follow pointer");
follow->setIsOn(true);
toolbar->addWidget(follow);
toolbar->addStretch();
column->addLayout(toolbar);
column->addWidget(view);

// Keep view-wide controls outside the projection so their drag targets stay still.
auto* controls = new QWidget(panel);
controls->setObjectName("spatialViewControls");
auto* grid = new QGridLayout(controls);
grid->setContentsMargins(0, 0, 0, 0);
grid->setHorizontalSpacing(24);
grid->setVerticalSpacing(12);
grid->setColumnStretch(0, 1);
grid->setColumnStretch(1, 1);
const auto addSlider = [controls, grid](const QString& name, const QString& label,
                                      const QString& unit, int minimum, int maximum,
                                      int initial, int row, int col) {
    auto* group = new QWidget(controls);
    auto* layout = new QVBoxLayout(group);
    layout->setContentsMargins(0, 0, 0, 0);
    layout->setSpacing(4);
    auto* text = new textfields::Label(group);
    text->setTextColorRole(textfields::Label::TextColorRole::Primary);
    auto* slider = new basicinput::Slider(group);
    slider->setObjectName(name);
    slider->setAccessibleName(label);
    slider->setRange(minimum, maximum);
    slider->setValue(initial);
    const auto updateText = [text, label, unit](int value) {
        text->setText(QString("%1: %2%3").arg(label).arg(value).arg(unit));
    };
    updateText(initial);
    QObject::connect(slider, &basicinput::Slider::valueChanged, text, updateText);
    layout->addWidget(text);
    layout->addWidget(slider);
    grid->addWidget(group, row, col);
    return slider;
};
auto* distance = addSlider("spatialViewDistance", "Camera distance", " px",
                           650, 2400, 1200, 0, 0);
auto* zoom = addSlider("spatialViewZoom", "Scene zoom", "%", 50, 110, 90, 0, 1);
QObject::connect(distance, &basicinput::Slider::valueChanged, view,
                 [view](int value) { view->setCameraDistance(value); });
QObject::connect(zoom, &basicinput::Slider::valueChanged, view,
                 [view](int value) { view->setZoom(value / 100.0); });
column->addWidget(controls);

QObject::connect(follow, &basicinput::ToggleSwitch::toggled,
                 view, &spatial::SpatialView::setPointerTrackingEnabled);
QObject::connect(view, &spatial::SpatialView::pointerTrackingEnabledChanged,
                 follow, &basicinput::ToggleSwitch::setIsOn);
const auto updateAvailability = [view, controls, follow] {
    controls->setEnabled(view->isSpatialEnabled());
    follow->setEnabled(view->isSpatialEnabled());
};
QObject::connect(view, &spatial::SpatialView::spatialEnabledChanged, controls, updateAvailability);
updateAvailability();

fluent::spatial::SpatialView

Inherits QWidget · FluentElement · QMLPlus

OpenGL-backed host for a small number of perspective-transformed live widgets.

Constructors

Properties

bool spatialEnabled

Enables perspective; default true when motion/theme policy permits it. False restores the same widgets in a native vertical layout with their state intact.

Read isSpatialEnabled()Write setSpatialEnabled()Notify spatialEnabledChanged()
qreal cameraDistance

Perspective distance in logical pixels [100, 10000]; default 1000. A shorter distance increases the apparent size difference between near and far surfaces.

Read cameraDistance()Write setCameraDistance()Notify cameraDistanceChanged()
qreal zoom

Whole-scene magnification [0.1, 4]; default 1. Item poses stay unchanged.

Read zoom()Write setZoom()Notify zoomChanged()
bool pointerTrackingEnabled

Tilts the whole scene toward the pointer; default true, active in 3D only.

Read isPointerTrackingEnabled()Write setPointerTrackingEnabled()Notify pointerTrackingEnabledChanged()
QPointF maximumTilt

Maximum pointer pitch/yaw, each [0, 45] degrees; default (10, 16).

Read maximumTilt()Write setMaximumTilt()Notify maximumTiltChanged()
int responseTime

Exponential pointer response time [0, 1000] ms; default 140, zero is immediate. Larger values soften the response; this is a time constant, not an animation duration.

Read responseTime()Write setResponseTime()Notify responseTimeChanged()
int maximumFrameRate

Pointer animation update cap [15, 120] fps; default 60, not measured display FPS.

Read maximumFrameRate()Write setMaximumFrameRate()Notify maximumFrameRateChanged()
bool cacheEnabled

Caches widget surfaces; default true. Changed content still repaints.

Read isCacheEnabled()Write setCacheEnabled()Notify cacheEnabledChanged()
RenderMode renderMode

Requested renderer: Auto (default), Raster or OpenGL; OpenGL may fall back. Switching waits until active pointer input finishes; inspect activeBackend for the result. Clipped/hidden views release their GPU viewport. Ancestor graphics effects use Raster so the outer compositor can capture the scene; the requested mode remains unchanged.

Read renderMode()Write setRenderMode()Notify renderModeChanged()
Backend activeBackend

Actual renderer, Raster or OpenGL; read-only, initially Raster until exposed.

Read activeBackend()Notify rendererChanged()
QString rendererName

Active OpenGL device name; read-only, empty for Raster or before initialization.

Read rendererName()Notify rendererChanged()
QString fallbackReason

Explanation of automatic renderer fallback; read-only, empty when none applies.

Read fallbackReason()Notify rendererChanged()
int itemCount

Number of hosted surfaces, including hidden ones; read-only, initially 0. Externally destroyed content is removed immediately; its notification is coalesced until widget teardown finishes, so handlers may destroy the host.

Read itemCount()Notify itemCountChanged()

Methods

SpatialItem* addWidget(QWidget* widget, WidgetOwnership ownership = WidgetOwnership::Borrowed)

Hosts a supported widget; null/unsupported/already-hosted content is rejected.

QWidget* takeWidget(SpatialItem* item)

Detaches content and deletes the item, transferring ownership to the caller.

void releaseItem(SpatialItem* item)

Deletes the item and applies its recorded widget ownership policy.

int itemCount() const

Number of hosted surfaces, including hidden ones; read-only, initially 0. Externally destroyed content is removed immediately; its notification is coalesced until widget teardown finishes, so handlers may destroy the host.

bool isSpatialEnabled() const

Enables perspective; default true when motion/theme policy permits it. False restores the same widgets in a native vertical layout with their state intact.

void setSpatialEnabled(bool enabled)

Enables perspective; default true when motion/theme policy permits it. False restores the same widgets in a native vertical layout with their state intact.

qreal cameraDistance() const

Perspective distance in logical pixels [100, 10000]; default 1000. A shorter distance increases the apparent size difference between near and far surfaces.

void setCameraDistance(qreal distance)

Perspective distance in logical pixels [100, 10000]; default 1000. A shorter distance increases the apparent size difference between near and far surfaces.

qreal zoom() const

Whole-scene magnification [0.1, 4]; default 1. Item poses stay unchanged.

void setZoom(qreal zoom)

Whole-scene magnification [0.1, 4]; default 1. Item poses stay unchanged.

bool isPointerTrackingEnabled() const

Tilts the whole scene toward the pointer; default true, active in 3D only.

void setPointerTrackingEnabled(bool enabled)

Tilts the whole scene toward the pointer; default true, active in 3D only.

QPointF maximumTilt() const

Maximum pointer pitch/yaw, each [0, 45] degrees; default (10, 16).

void setMaximumTilt(const QPointF& degrees)

Maximum pointer pitch/yaw, each [0, 45] degrees; default (10, 16).

int responseTime() const

Exponential pointer response time [0, 1000] ms; default 140, zero is immediate. Larger values soften the response; this is a time constant, not an animation duration.

void setResponseTime(int milliseconds)

Exponential pointer response time [0, 1000] ms; default 140, zero is immediate. Larger values soften the response; this is a time constant, not an animation duration.

int maximumFrameRate() const

Pointer animation update cap [15, 120] fps; default 60, not measured display FPS.

void setMaximumFrameRate(int framesPerSecond)

Pointer animation update cap [15, 120] fps; default 60, not measured display FPS.

bool isCacheEnabled() const

Caches widget surfaces; default true. Changed content still repaints.

void setCacheEnabled(bool enabled)

Caches widget surfaces; default true. Changed content still repaints.

RenderMode renderMode() const

Requested renderer: Auto (default), Raster or OpenGL; OpenGL may fall back. Switching waits until active pointer input finishes; inspect activeBackend for the result. Clipped/hidden views release their GPU viewport. Ancestor graphics effects use Raster so the outer compositor can capture the scene; the requested mode remains unchanged.

void setRenderMode(RenderMode mode)

Requested renderer: Auto (default), Raster or OpenGL; OpenGL may fall back. Switching waits until active pointer input finishes; inspect activeBackend for the result. Clipped/hidden views release their GPU viewport. Ancestor graphics effects use Raster so the outer compositor can capture the scene; the requested mode remains unchanged.

Backend activeBackend() const

Actual renderer, Raster or OpenGL; read-only, initially Raster until exposed.

QString rendererName() const

Active OpenGL device name; read-only, empty for Raster or before initialization.

QString fallbackReason() const

Explanation of automatic renderer fallback; read-only, empty when none applies.

Signals

void spatialEnabledChanged(bool enabled)

Enables perspective; default true when motion/theme policy permits it. False restores the same widgets in a native vertical layout with their state intact.

void cameraDistanceChanged(qreal distance)

Perspective distance in logical pixels [100, 10000]; default 1000. A shorter distance increases the apparent size difference between near and far surfaces.

void zoomChanged(qreal zoom)

Whole-scene magnification [0.1, 4]; default 1. Item poses stay unchanged.

void pointerTrackingEnabledChanged(bool enabled)

Tilts the whole scene toward the pointer; default true, active in 3D only.

void maximumTiltChanged(const QPointF& degrees)

Maximum pointer pitch/yaw, each [0, 45] degrees; default (10, 16).

void responseTimeChanged(int milliseconds)

Exponential pointer response time [0, 1000] ms; default 140, zero is immediate. Larger values soften the response; this is a time constant, not an animation duration.

void maximumFrameRateChanged(int framesPerSecond)

Pointer animation update cap [15, 120] fps; default 60, not measured display FPS.

void cacheEnabledChanged(bool enabled)

Caches widget surfaces; default true. Changed content still repaints.

void renderModeChanged(RenderMode mode)

Requested renderer: Auto (default), Raster or OpenGL; OpenGL may fall back. Switching waits until active pointer input finishes; inspect activeBackend for the result. Clipped/hidden views release their GPU viewport. Ancestor graphics effects use Raster so the outer compositor can capture the scene; the requested mode remains unchanged.

void rendererChanged()

Actual renderer, Raster or OpenGL; read-only, initially Raster until exposed.

void itemCountChanged(int count)

Number of hosted surfaces, including hidden ones; read-only, initially 0. Externally destroyed content is removed immediately; its notification is coalesced until widget teardown finishes, so handlers may destroy the host.

Enumerations

enum class RenderMode
  • Auto
  • Raster
  • OpenGL
enum class Backend
  • Raster
  • OpenGL

Destructors

PySide6 additions

addOwnedWidget(widget)

Transfer content to the view; releasing its item destroys it.

addReparentedWidget(widget)

Restore content to its original QWidget parent on release.

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