Fluent-Qt

Menus & toolbars

Menu

A list of commands shown in a transient surface.

Example

Menu: Commands and shortcuts

Usage

Commands and shortcuts

Menu commands can expose native shortcuts and update app state when triggered.

#include <FluentQt/MenusToolbars.h>
using namespace fluent::menus_toolbars;

using fluent::status_info::Toast;
auto addCommand = [this](FluentMenu* menu, const QString& text,
                         const QKeySequence& shortcut = QKeySequence()) {
    auto* action = menu->addAction(text);
    if (!shortcut.isEmpty()) action->setShortcut(shortcut);
    connect(action, &QAction::triggered, this, [this, text] {
        Toast::showOrUpdateToast(this, "gallery.action-feedback", text + " selected",
            Toast::Informational, 2200, Toast::Top, QMargins(16, 50, 16, 16));
    });
    return action;
};
auto* button = new DropDownButton("File", this);
auto* menu = new FluentMenu(QString(), button);
addCommand(menu, "New", QKeySequence::New);
addCommand(menu, "Open...", QKeySequence::Open);
addCommand(menu, "Save", QKeySequence::Save);
menu->addSeparator();
menu->addAction("Publish")->setEnabled(false);
addCommand(menu, "Close");
button->setMenu(menu);

fluent::menus_toolbars::FluentMenu

Inherits QMenu · FluentElement · QMLPlus

Fluent-styled QMenu with token-driven item typography.

Constructors

Properties

Typography::FontRole fontStyle

Fluent typography style used by menu text.

Read fontStyle()Write setFontStyle()Notify fontStyleChanged()

Methods

void setFontStyle(Typography::FontRole role)

设置菜单的字体角色,默认 Typography::FontRole::Body。

Typography::FontRole fontStyle() const

Fluent typography style used by menu text.

Signals

void fontStyleChanged()

Fluent typography style used by menu text.

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

fluent::menus_toolbars::FluentMenuItem

Inherits QWidgetAction · FluentElement · QMLPlus

Menu item action with Fluent typography metadata.

Constructors

Properties

Typography::FontRole fontStyle

Fluent typography style used by menu text.

Read fontStyle()Write setFontStyle()Notify fontStyleChanged()

Methods

void setFontStyle(Typography::FontRole role)

设置菜单项的字体角色,默认 Typography::FontRole::Body。

Typography::FontRole fontStyle() const

Fluent typography style used by menu text.

Signals

void fontStyleChanged()

Fluent typography style used by menu text.