Fluent-Qt

Basic input

ToggleSwitch

A switch that flips between on and off states.

Example

ToggleSwitch: ToggleSwitch state

Usage

ToggleSwitch state

The toggled signal mirrors the on/off state into surrounding UI.

#include <FluentQt/BasicInput.h>
using namespace fluent::basicinput;

auto* toggle = new ToggleSwitch(this);
toggle->setOnContent("On");
toggle->setOffContent("Off");
toggle->setAccessibleName("Feature toggle");
auto* status = new Label("State: Off", this);
connect(toggle, &ToggleSwitch::toggled,
        status, [status](bool on) {
            status->setText(on ? "State: On" : "State: Off");
        });

fluent::basicinput::ToggleSwitch

Inherits QWidget · FluentElement · QMLPlus

Fluent switch for binary on/off settings.

Constructors

Properties

bool isOn

Current on/off state of the switch.

Read isOn()Write setIsOn()Notify toggled()
QString onContent

Text shown for the on state.

Read onContent()Write setOnContent()Notify onContentChanged()
QString offContent

Text shown for the off state.

Read offContent()Write setOffContent()Notify offContentChanged()
Typography::FontRole fontRole

Fluent typography role used while the switch follows theme fonts.

Read fontRole()Write setFontRole()Notify fontRoleChanged()
qreal visualScale

Scale of the switch graphics and content gap, independent of widget size and font.

Read visualScale()Write setVisualScale()Notify visualScaleChanged()
qreal knobPosition

Animated switch knob position, normalized from off to on.

Read knobPosition()Write setKnobPosition()

Methods

bool isOn() const

Current on/off state of the switch.

void setIsOn(bool on)

Current on/off state of the switch.

QString onContent() const

Text shown for the on state.

void setOnContent(const QString& content)

Text shown for the on state.

QString offContent() const

Text shown for the off state.

void setOffContent(const QString& content)

Text shown for the off state.

Typography::FontRole fontRole() const

Fluent typography role used while the switch follows theme fonts.

void setFontRole(Typography::FontRole role)

Fluent typography role used while the switch follows theme fonts.

qreal visualScale() const

Scale of the switch graphics and content gap, independent of widget size and font.

void setVisualScale(qreal scale)

Sets the visual scale and updates layout hints without resizing a fixed widget.

void setFont(const QFont& font)

Sets an explicit font that remains unchanged by later theme refreshes.

qreal knobPosition() const

Animated switch knob position, normalized from off to on.

void setKnobPosition(qreal pos)

Animated switch knob position, normalized from off to on.

Signals

void toggled(bool isOn)

Current on/off state of the switch.

void fontRoleChanged()

Fluent typography role used while the switch follows theme fonts.

void visualScaleChanged(qreal scale)

Scale of the switch graphics and content gap, independent of widget size and font.

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