Fluent-Qt

Status & info

Toast

Shows a brief same-window notification without interrupting the current task.

Example

Toast: Messages

Usage

Messages

Timely feedback, with a clear next step. Hover pauses the timeout; close or use an action to continue.

#include <FluentQt/StatusInfo.h>
using namespace fluent::status_info;

auto* panel = new QWidget(this);
auto* layout = new QVBoxLayout(panel);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(12);
auto* retry = new QAction("Try again", panel);
QObject::connect(retry, &QAction::triggered, panel, [panel]() {
    Toast::showToast(panel, "Ready to retry", Toast::Success, 2200, Toast::TopEnd);
});
auto* review = new QAction("Review file", panel);
QObject::connect(review, &QAction::triggered, panel, [panel]() {
    Toast::showToast(panel, "Choose a file under 20 MB", Toast::Informational, 3500, Toast::TopEnd);
});
auto* row = new QWidget(panel);
auto* buttons = new QHBoxLayout(row);
buttons->setContentsMargins(0, 0, 0, 0);
buttons->setSpacing(8);
const QStringList labels = {"Saved", "Copied", "Warning", "Error"};
for (int i = 0; i < labels.size(); ++i) {
    auto* button = new Button(labels.at(i), row);
    button->setObjectName(QStringLiteral("feedback%1").arg(i));
    buttons->addWidget(button);
    QObject::connect(button, &Button::clicked, panel, [panel, retry, review, i]() {
        for (Toast* previous : panel->window()->findChildren<Toast*>("feedbackToast"))
            previous->dismiss();
        auto* toast = new Toast(panel);
        toast->setObjectName("feedbackToast");
        toast->setDuration(5500);
        toast->setPlacement(Toast::TopEnd);
        toast->setClosable(true);
        toast->setPauseOnHoverEnabled(true);
        if (i == 0 || i == 1) {
            toast->setSeverity(i == 0 ? Toast::Success : Toast::Informational);
            toast->setMessage(i == 0 ? "Changes saved" : "Link copied");
        } else if (i == 2) {
            toast->setSeverity(Toast::Warning);
            toast->setTitle("One file needs attention");
            toast->setMessage("archive.zip exceeds the 20 MB limit. The other files can continue.");
            toast->setAction(review);
        } else {
            toast->setSeverity(Toast::Error);
            toast->setTitle("Upload interrupted");
            toast->setMessage("Your connection was lost. Try again to resume product-shot.png.");
            toast->setAction(retry);
        }
        QObject::connect(panel, &QObject::destroyed, toast, &QObject::deleteLater);
        QObject::connect(toast, &Toast::dismissed, toast, &QObject::deleteLater);
        toast->present(panel);
    });
}
buttons->addStretch();
layout->addWidget(row);

fluent::status_info::Toast

Inherits QWidget · FluentElement · QMLPlus

Transient same-window notification with severity and edge placement.

Constructors

Properties

QString title
Read title()Write setTitle()Notify titleChanged()
QString message
Read message()Write setMessage()Notify messageChanged()
Severity severity
Read severity()Write setSeverity()Notify severityChanged()
Placement placement
Read placement()Write setPlacement()Notify placementChanged()
QMargins placementMargins
Read placementMargins()Write setPlacementMargins()Notify placementMarginsChanged()
int duration
Read duration()Write setDuration()Notify durationChanged()
bool animationEnabled
Read isAnimationEnabled()Write setAnimationEnabled()Notify animationEnabledChanged()
QAction* action

Optional caller-owned action presented inside the toast.

Read action()Write setAction()Notify actionChanged()
bool closable

Whether a close button dismisses the toast with `CloseButton`.

Read isClosable()Write setClosable()Notify closableChanged()
bool pauseOnHoverEnabled

Whether an active duration timer pauses while the toast is hovered.

Read isPauseOnHoverEnabled()Write setPauseOnHoverEnabled()Notify pauseOnHoverEnabledChanged()
QString updateKey

Optional key used by `showOrUpdateToast()` within one managed stack.

Read updateKey()Write setUpdateKey()Notify updateKeyChanged()
bool isOpen
Read isOpen()Notify isOpenChanged()
qreal toastProgress
Read toastProgress()Write setToastProgress()

Methods

QAction* action() const

Optional caller-owned action presented inside the toast.

void setAction(QAction* action)

Optional caller-owned action presented inside the toast.

bool isClosable() const

Whether a close button dismisses the toast with `CloseButton`.

void setClosable(bool closable)

Whether a close button dismisses the toast with `CloseButton`.

bool isPauseOnHoverEnabled() const

Whether an active duration timer pauses while the toast is hovered.

void setPauseOnHoverEnabled(bool enabled)

Whether an active duration timer pauses while the toast is hovered.

QString updateKey() const

Optional key used by `showOrUpdateToast()` within one managed stack.

void setUpdateKey(const QString& key)

Optional key used by `showOrUpdateToast()` within one managed stack.

static int maximumVisible()

Maximum managed toasts kept visible per host and placement.

bool present(QWidget* anchor)

Presents this toast in the anchor's top-level window.

void dismiss()

Dismisses the toast and ends its current display lifetime.

Signals

void actionChanged(QAction* action)

Optional caller-owned action presented inside the toast.

void closableChanged(bool closable)

Whether a close button dismisses the toast with `CloseButton`.

void pauseOnHoverEnabledChanged(bool enabled)

Whether an active duration timer pauses while the toast is hovered.

void updateKeyChanged(const QString& key)

Optional key used by `showOrUpdateToast()` within one managed stack.

Enumerations

enum Severity
  • Informational
  • Success
  • Warning
  • Error
enum Placement

Edge anchor for the toast card.

  • TopStart
  • Top
  • TopEnd
  • BottomStart
  • Bottom
  • BottomEnd
enum DismissReason

Reason that ended one toast presentation lifetime.

  • Programmatic
  • TimedOut
  • ActionInvoked
  • Evicted
  • CloseButton

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