Fluent-Qt

Menus & toolbars

CommandBar

A responsive command strip with primary and overflow actions.

Example

CommandBar: A responsive document command strip

Usage

A responsive document command strip

Try priority-aware overflow, icon or right-side labels, primary and secondary sections, separators, and an optional command-bar background.

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

auto* barHost = new QWidget(this);
barHost->setFixedWidth(536);
auto* barLayout = new QHBoxLayout(barHost);
barLayout->setContentsMargins(0, 0, 0, 0);
auto* bar = new CommandBar(barHost);
bar->setAccessibleName("Document commands");
bar->setLabelPosition(
    CommandBar::LabelPosition::Right);
bar->setBackgroundVisible(false);
barLayout->addWidget(bar);

auto* addAction = new QAction(
    QIcon(":/icons/add.svg"), "Add", this);
auto* editAction = new QAction(
    QIcon(":/icons/edit.svg"), "Edit", this);
editAction->setPriority(QAction::HighPriority);
auto* shareAction = new QAction(
    QIcon(":/icons/share.svg"), "Share", this);
auto* separator = new QAction(this);
separator->setSeparator(true);
auto* syncAction = new QAction(
    QIcon(":/icons/sync.svg"), "Sync", this);
syncAction->setPriority(QAction::LowPriority);
auto* pinAction = new QAction(
    QIcon(":/icons/pin.svg"), "Pin", this);
pinAction->setCheckable(true);

bar->addPrimaryAction(addAction);
bar->addPrimaryAction(editAction);
bar->addPrimaryAction(shareAction);
bar->addPrimaryAction(separator);
bar->addPrimaryAction(syncAction);
bar->addPrimaryAction(pinAction);
bar->addSecondaryAction(new QAction(
    QIcon(":/icons/settings.svg"), "Settings", this));
bar->addSecondaryAction(new QAction(
    QIcon(":/icons/help.svg"), "Help", this));

auto* compactButton =
    new Button("Compact view", this);
auto* labelsButton =
    new Button("Labels: Right", this);
auto* backgroundButton =
    new Button("Show background", this);
connect(compactButton, &Button::clicked, barHost,
        [barHost] {
            barHost->setFixedWidth(
                barHost->width() > 300 ? 288 : 536);
        });
connect(labelsButton, &Button::clicked, bar, [=] {
    const bool showLabels =
        bar->labelPosition()
        == CommandBar::LabelPosition::Collapsed;
    bar->setLabelPosition(
        showLabels
            ? CommandBar::LabelPosition::Right
            : CommandBar::LabelPosition::Collapsed);
});
connect(backgroundButton, &Button::clicked, bar, [=] {
    bar->setBackgroundVisible(
        !bar->backgroundVisible());
});
using fluent::status_info::Toast;
for (QAction* action : bar->primaryActions() + bar->secondaryActions()) {
    if (action->isSeparator()) continue;
    connect(action, &QAction::triggered, this, [this, action] {
        QString text = action->text().section('\t', 0, 0).remove('&');
        Toast::showOrUpdateToast(this, "gallery.action-feedback", text + " selected",
            Toast::Informational, 2200, Toast::Top, QMargins(16, 50, 16, 16));
    });
}

fluent::menus_toolbars::CommandBar

Inherits QWidget · FluentElement · QMLPlus

Hosts ordered primary and secondary application commands.

Constructors

Properties

LabelPosition labelPosition
Read labelPosition()Write setLabelPosition()Notify labelPositionChanged()
bool dynamicOverflowEnabled
Read isDynamicOverflowEnabled()Write setDynamicOverflowEnabled()Notify dynamicOverflowEnabledChanged()
bool overflowOpen
Read isOverflowOpen()Write setOverflowOpen()Notify overflowOpenChanged()
bool backgroundVisible
Read backgroundVisible()Write setBackgroundVisible()Notify backgroundVisibleChanged()

Methods

void addAction(QAction* action)

Adds a QAction through the Qt widget API as a primary command.

void insertAction(QAction* before, QAction* action)

Inserts a new Qt widget action into primary command order.

void removeAction(QAction* action)

Removes Qt widget association and semantic command membership.

bool addPrimaryAction(QAction* action)

Appends a borrowed action to the primary section.

bool insertPrimaryAction(QAction* before, QAction* action)

Inserts a borrowed primary action before another primary action.

bool addSecondaryAction(QAction* action)

Appends a borrowed action to the secondary section.

bool insertSecondaryAction(QAction* before, QAction* action)

Inserts a borrowed secondary action before another secondary action.

bool removeCommandAction(QAction* action)

Removes an action from either semantic section without deleting it.

void clearPrimaryActions()

Clears primary membership without deleting actions.

void clearSecondaryActions()

Clears secondary membership without deleting actions.

QList<QAction*> primaryActions() const

Returns primary actions in semantic order.

QList<QAction*> secondaryActions() const

Returns secondary actions in semantic order.

QList<QAction*> overflowedPrimaryActions() const

Returns the current presentation-only overflow snapshot.

bool isPrimaryActionOverflowed(const QAction* action) const

Returns whether a primary action is currently overflowed.

void setOverflowOpen(bool open)

Opens or closes the overflow presentation when one is available.

Signals

Enumerations

enum class LabelPosition

Controls whether inline command labels are shown beside icons.

  • Collapsed
  • Right

Types and aliases

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