Fluent-Qt

メニューとツールバー

CommandBar コマンドバー

プライマリアクションとオーバーフローアクションを備えたレスポンシブなコマンドストリップです。

サンプル

CommandBar コマンドバー: レスポンシブなドキュメントコマンドストリップ

使い方

レスポンシブなドキュメントコマンドストリップ

優先度に応じたオーバーフロー、アイコンまたは右側のラベル、プライマリとセカンダリのセクション、区切り線、オプションのコマンドバー背景を試せます。

#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

継承元 QWidget · FluentElement · QMLPlus

主要なアクションをインラインで表示し、収まらない項目を右側のオーバーフローメニューへ移動する水平コマンドバーです。

コンストラクタ

デストラクタ

列挙型

enum class LabelPosition

インラインコマンドのラベルをアイコンの横に表示するかどうかを制御します。

  • Collapsed
  • Right

メソッド

void addAction(QAction* action)

所有権を取得せずにプライマリセクションへアクションを追加します。

void insertAction(QAction* before, QAction* action)

所有権を取得せずに、プライマリセクション内の `before` の前にアクションを挿入します。

void removeAction(QAction* action)

アクションを破棄せずに、バーから削除します。

bool addPrimaryAction(QAction* action)

所有権を取得せずにプライマリセクションの末尾へアクションを追加します。

bool insertPrimaryAction(QAction* before, QAction* action)

所有権を取得せずに、`before` の前にプライマリアクションを挿入します。

bool addSecondaryAction(QAction* action)

所有権を取得せずにセカンダリ(オーバーフロー)セクションの末尾へアクションを追加します。

bool insertSecondaryAction(QAction* before, QAction* action)

所有権を取得せずに、`before` の前にセカンダリアクションを挿入します。

bool removeCommandAction(QAction* action)

アクションを破棄せずに、プライマリまたはセカンダリコマンドから削除します。

void clearPrimaryActions()

アクションを削除せずに、すべてのプライマリコマンドをクリアします。

void clearSecondaryActions()

アクションを削除せずに、すべてのセカンダリコマンドをクリアします。

QList<QAction*> primaryActions() const

プライマリアクションを表示順で返します。

QList<QAction*> secondaryActions() const

セカンダリアクションを表示順で返します。

QList<QAction*> overflowedPrimaryActions() const

現在オーバーフローメニューに移動されているプライマリアクションを返します。

bool isPrimaryActionOverflowed(const QAction* action) const

プライマリアクションが現在オーバーフローメニュー内にあるかどうかを返します。

void setOverflowOpen(bool open)

オーバーフロー項目が存在する場合にオーバーフローメニューを開閉します。

プロパティ

LabelPosition labelPosition
読み取り labelPosition()書き込み setLabelPosition()通知シグナル labelPositionChanged()
bool dynamicOverflowEnabled
読み取り isDynamicOverflowEnabled()書き込み setDynamicOverflowEnabled()通知シグナル dynamicOverflowEnabledChanged()
bool overflowOpen
読み取り isOverflowOpen()書き込み setOverflowOpen()通知シグナル overflowOpenChanged()
bool backgroundVisible
読み取り backgroundVisible()書き込み setBackgroundVisible()通知シグナル backgroundVisibleChanged()

シグナル

型とエイリアス

protected メンバー

メソッド

fluent::FluentElement から継承

列挙型

enum Theme

デザイントークン解決時に使用されるグローバルな視覚テーマ。

  • Light = 0
  • Dark = 1
  • HighContrast = 2

メソッド

static void setTheme(Theme theme)

グローバルテーマを更新し、アクティブな FluentElement インスタンスに通知します。

static void setThemeDeferred(Theme theme)

現在の操作をブロックせずに、可視要素を優先したバッチ処理でテーマの更新をスケジュールします。

static Theme currentTheme()

現在有効なグローバルテーマを返します。

static bool themeUsesDarkAppearance(Theme theme)

テーマがダークベースのクロームおよびマテリアルトークンを使用するかどうかを返します。

static void refreshTheme()

デザイントークンの変更後に再描画するため、現在のテーマを再ブロードキャストします。

static int themeGeneration()

テーマ変更ごとに加算される単調増加カウンターです。鮮度チェックに使用されます。

Theme effectiveTheme() const

継承された QWidget の上書きを尊重し、この要素が使用するテーマを解決します。

bool effectiveThemeUsesDarkAppearance() const

この要素の有効なテーマがダークベースのクロームを使用するかどうかを返します。

bool setThemeOverrides(const QJsonObject& overrides)

この要素のスパースな色、角丸半径、フォントトークンの上書きを置き換えます。

QJsonObject themeOverrides() const

この要素に設定されたオーバーライドを返します。

void clearThemeOverrides()

すべてのトークンフィールドをグローバルテーマの既定値に復元します。

const Colors& themeColorsRef() const

描画のホットパス向けにアクティブなカラーセットへ非コピーでアクセスします。

Material::AcrylicToken themeAcrylic() const

マテリアル、エレベーション、およびアダプティブレイアウトのトークン。

QColor themeBackdrop(bool active) const

指定されたアクティブ状態に対するウィンドウ chrome の背景色。

virtual void onThemeUpdated()

グローバルテーマの変更後に呼び出されます。

型とエイリアス

struct Colors

コンポーネントに返されるデザイントークンのスナップショット。

fluent::QMLPlus から継承

メソッド

AnchorLayout::Anchors* anchors()

QWidget ホストの変更可能なアンカーを返します。

void setState(const QString& name)

登録済みの状態を名前で適用するか、@p name が空の場合はデフォルト状態を復元します。未知の名前は無視され、その状態を離れると既存のバインディングが再開されます。

void addState(const QMLState& state)

名前付き状態定義を登録または置換します。アクティブな状態を置換した場合は即座に適用されます。

void evaluateStates()

登録順に状態条件を再評価し、最初に一致した状態(一致しない場合はデフォルト状態)をアクティブにします。依存プロパティの変更通知時にも自動実行され、extend を使用する派生状態は、循環や欠損がない限り祖先の変更を継承します。

QMLPlusRuntime* runtime()

このホストが所有し、遅延生成される状態オブザーバーを返します。

void setAnchors(const AnchorLayout::Anchors& anchors)

すべてのホストアンカーを置き換え、親レイアウトを無効化します。

void resetAnchors()

ホストのすべてのアンカーをクリアし、親レイアウトを無効化します。

void bind(const char* targetProp, QObject* source, const char* sourceProp, PropertyBinder::Direction dir = PropertyBinder::OneWay)

PropertyBinder::bind() を介して、@p source の @p sourceProp をこの QWidget ホストの @p targetProp にバインドします。

void addTransition(const StateTransition& transition)

優先順位順に状態遷移を登録します。

void setBehavior(const char* propertyName, const PropertyAnimation& animation)

writeProperty() またはバインディング経由で @p propertyName が書き込まれた際に使用されるデフォルトアニメーションを設定します。明示的な StateTransition ルールが優先され、C++ のセッターを直接呼び出した場合はアニメーションしません。

void clearBehavior(const char* propertyName)

今後のマネージド書き込みに使用するデフォルトアニメーションを削除します。

bool writeProperty(const char* propertyName, const QVariant& value)

バインディングを削除せずに Behavior 経由でホストプロパティに書き込みます。

Qt 基底クラスドキュメント:QWidget