Fluent-Qt

Basic input

Button

Run an action, such as saving or submitting a form.

Example

Real FluentQt Standard, Accent and Subtle buttons

Usage

Choose a style

Set the style with setFluentStyle(): Accent for the main action, Standard for other actions, and Subtle for less prominent ones.

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

auto* standard = new Button("Standard", this);
standard->setFluentStyle(Button::Standard);

auto* accent = new Button("Accent", this);
accent->setFluentStyle(Button::Accent);

auto* subtle = new Button("Subtle", this);
subtle->setFluentStyle(Button::Subtle);

Interaction states

Button renders rest, hover, pressed, and disabled states directly. Call setFocusVisual(true) to show the focus ring when focused via keyboard.

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

auto* rest = new Button("Rest", this);

auto* hover = new Button("Hover", this);
hover->setInteractionState(Button::Hover);

auto* pressed = new Button("Pressed", this);
pressed->setInteractionState(Button::Pressed);

auto* focused = new Button("Focus", this);
focused->setFocusVisual(true);

auto* disabled = new Button("Disabled", this);
disabled->setInteractionState(Button::Disabled);

fluent::basicinput::Button

Inherits QPushButton · FluentElement · QMLPlus

Fluent push button with token-driven painting and optional iconfont content. Keeps QPushButton interaction behavior while custom-painting in paintEvent().

Constructors

Properties

ButtonStyle fluentStyle

Visual treatment: Standard, Accent, or Subtle.

Read fluentStyle()Write setFluentStyle()Notify fluentStyleChanged()
ButtonSize fluentSize

Size preset controlling height and padding, not font.

Read fluentSize()Write setFluentSize()Notify fluentSizeChanged()
Typography::FontRole fontRole

Fluent Typography preset used while following theme fonts.

Read fontRole()Write setFontRole()Notify fontRoleChanged()
TextColorRole textColorRole

Foreground emphasis for unfilled, unchecked buttons; filled and disabled keep contrast colors.

Read textColorRole()Write setTextColorRole()Notify textColorRoleChanged()
ButtonLayout fluentLayout

Content layout for text and icon placement.

Read fluentLayout()Write setFluentLayout()Notify fluentLayoutChanged()
QIcon icon

Qt icon with the same default-layout promotion as icon glyphs.

Read icon()Write setIcon()Notify iconChanged()
bool focusVisual

Controls whether the focus visual frame is painted.

Read hasFocusVisual()Write setFocusVisual()Notify focusVisualChanged()
InteractionState interactionState

Overrides the interaction state for guided demos or visual checks.

Read interactionState()Write setInteractionState()Notify interactionStateChanged()
bool criticalOnHover

Uses the critical error color while hovered or pressed.

Read criticalOnHover()Write setCriticalOnHover()Notify criticalOnHoverChanged()
QMargins cornerRadii

Per-corner radii; left/top/right/bottom map to top-left/top-right/bottom-right/bottom-left.

Read cornerRadii()Write setCornerRadii()Reset resetCornerRadii()Notify cornerRadiiChanged()
QPoint iconOffset

Pixel offset applied to iconfont drawing; positive values move right/down.

Read iconOffset()Write setIconOffset()
qreal iconRotation

Clockwise rotation applied to the painted icon in degrees.

Read iconRotation()Write setIconRotation()
qreal iconScale

Uniform scale applied to the painted iconfont glyph (1.0 = no scaling). Applications can animate this property for press feedback; Button does not start a scale animation itself.

Read iconScale()Write setIconScale()
qreal contentOpacity

Painter-level opacity for the whole button (1.0 = fully opaque). Lightweight fade that avoids QGraphicsOpacityEffect's offscreen compositing overhead.

Read contentOpacity()Write setContentOpacity()

Methods

ButtonStyle fluentStyle() const

Visual treatment: Standard, Accent, or Subtle.

void setFluentStyle(ButtonStyle style)

Visual treatment: Standard, Accent, or Subtle.

ButtonSize fluentSize() const

Size preset controlling height and padding, not font.

void setFluentSize(ButtonSize size)

Size preset controlling height and padding, not font.

Typography::FontRole fontRole() const

Fluent Typography preset used while following theme fonts.

void setFontRole(Typography::FontRole role)

Fluent Typography preset used while following theme fonts.

TextColorRole textColorRole() const

Foreground emphasis for unfilled, unchecked buttons; filled and disabled keep contrast colors.

void setTextColorRole(TextColorRole role)

Foreground emphasis for unfilled, unchecked buttons; filled and disabled keep contrast colors.

void setFont(const QFont& font)

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

ButtonLayout fluentLayout() const

Content layout for text and icon placement.

void setFluentLayout(ButtonLayout layout)

Selects an explicit layout, including TextOnly before an icon is assigned.

void setIcon(const QIcon& icon)

Sets a Qt icon; the first icon uses IconBefore unless a layout was explicitly selected.

QIcon icon() const

Qt icon with the same default-layout promotion as icon glyphs.

bool hasFocusVisual() const

Controls whether the focus visual frame is painted.

void setFocusVisual(bool focus)

Controls whether the focus visual frame is painted.

InteractionState interactionState() const

Overrides the interaction state for guided demos or visual checks.

void setInteractionState(InteractionState state)

Overrides the interaction state for guided demos or visual checks.

bool criticalOnHover() const

Uses the critical error color while hovered or pressed.

void setCriticalOnHover(bool enabled)

Uses the critical error color while hovered or pressed.

QMargins cornerRadii() const

Per-corner radii; left/top/right/bottom map to top-left/top-right/bottom-right/bottom-left.

void setCornerRadii(const QMargins& radii)

Per-corner radii; left/top/right/bottom map to top-left/top-right/bottom-right/bottom-left.

void resetCornerRadii()

Per-corner radii; left/top/right/bottom map to top-left/top-right/bottom-right/bottom-left.

QPoint iconOffset() const

Pixel offset applied to iconfont drawing; positive values move right/down.

void setIconOffset(const QPoint& offset)

Pixel offset applied to iconfont drawing; positive values move right/down.

qreal iconRotation() const

Clockwise rotation applied to the painted icon in degrees.

void setIconRotation(qreal rotation)

Clockwise rotation applied to the painted icon in degrees.

qreal iconScale() const

Uniform scale applied to the painted iconfont glyph (1.0 = no scaling). Applications can animate this property for press feedback; Button does not start a scale animation itself.

void setIconScale(qreal scale)

Uniform scale applied to the painted iconfont glyph (1.0 = no scaling). Applications can animate this property for press feedback; Button does not start a scale animation itself.

qreal contentOpacity() const

Painter-level opacity for the whole button (1.0 = fully opaque). Lightweight fade that avoids QGraphicsOpacityEffect's offscreen compositing overhead.

void setContentOpacity(qreal opacity)

Painter-level opacity for the whole button (1.0 = fully opaque). Lightweight fade that avoids QGraphicsOpacityEffect's offscreen compositing overhead.

QSize sizeHint() const override

Computes preferred size including Fluent padding, text, and iconfont content.

void setIconGlyph(const QString& glyph, int pixelSize = Typography::IconSize::Standard, const QString& family = Typography::FontFamily::FluentIcons)

Sets an iconfont glyph drawn directly in paintEvent(). The first non-empty glyph switches layout to IconBefore unless setFluentLayout() was called.

Signals

void fluentStyleChanged()

Visual treatment: Standard, Accent, or Subtle.

void fluentSizeChanged()

Size preset controlling height and padding, not font.

void fontRoleChanged()

Fluent Typography preset used while following theme fonts.

void textColorRoleChanged()

Foreground emphasis for unfilled, unchecked buttons; filled and disabled keep contrast colors.

void fluentLayoutChanged()

Content layout for text and icon placement.

void iconChanged()

Qt icon with the same default-layout promotion as icon glyphs.

void focusVisualChanged()

Controls whether the focus visual frame is painted.

void interactionStateChanged()

Overrides the interaction state for guided demos or visual checks.

void criticalOnHoverChanged()

Uses the critical error color while hovered or pressed.

void cornerRadiiChanged()

Per-corner radii; left/top/right/bottom map to top-left/top-right/bottom-right/bottom-left.

Enumerations

enum ButtonStyle

Button visual style resolved against Fluent design tokens.

  • Standard
  • Accent
  • Subtle
enum ButtonSize

Button density presets for padding and preferred height.

  • Small
  • StandardSize
  • Large
enum ButtonLayout

Text/icon composition mode, including centered icons above or below the label.

  • TextOnly
  • IconBefore
  • IconOnly
  • IconAfter
  • IconAbove
  • IconBelow
enum class TextColorRole

Text and icon color emphasis level.

  • Primary
  • Secondary
  • Accent
enum InteractionState

Paint-state override; Rest uses the actual hover or press state.

  • Rest
  • Hover
  • Pressed
  • Disabled
Protected members

Methods

void paintEvent(QPaintEvent* event) override

Custom-paint the button instead of delegating to QStyle.

void paintButton(InteractionState state)

Paints a visual state without changing the interaction-state property.

void paintButtonState(InteractionState state, bool focused)

Paints an explicit focus state without moving focus; focusVisual and disabled state still apply.

virtual QRectF contentPaintRect(const QRectF& surfaceRect) const

Returns the rectangle used to lay out painted icon and text content.

virtual QSize stackedContentSize() const

Measures the stacked icon and label without outer padding.

QRectF paintStackedContent(QPainter& painter, const QRectF& bounds) const

Paints centered stacked content in the supplied bounds and returns the label rectangle.

QString iconGlyph() const

Exposes iconfont details to button subclasses.

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.

bool setThemeOverrides(const QJsonObject& overrides)

Replaces this element's sparse color, radius, and font token overrides.

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

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: QPushButton