Menüs & Symbolleisten
CommandBar Befehlsleiste
Eine responsive Befehlsleiste mit primären Aktionen und Überlaufmenü.
Beispiel
Die Eigenschaftsvorschau konnte nicht geladen werden. Wählen Sie „Eigenschaftsvorschau“, um es erneut zu versuchen.

Verwendung
Responsive Befehlsleiste für Dokumente
Prioritätsgesteuerten Überlauf, Symbol- oder rechtsseitige Beschriftungen, primäre und sekundäre Bereiche, Trennlinien sowie einen optionalen Hintergrund testen.
#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));
});
}import fluentqt
from PySide6.QtCore import QMargins
from PySide6.QtGui import QAction, QIcon
from PySide6.QtWidgets import QHBoxLayout, QWidget
bar_host = QWidget()
bar_host.setFixedWidth(536)
bar_layout = QHBoxLayout(bar_host)
bar_layout.setContentsMargins(0, 0, 0, 0)
bar = fluentqt.CommandBar(bar_host)
bar.setAccessibleName("Document commands")
bar.setLabelPosition(fluentqt.CommandBar.LabelPosition.Right)
bar.setBackgroundVisible(False)
bar_layout.addWidget(bar)
add_action = QAction(QIcon(":/icons/add.svg"), "Add", bar)
edit_action = QAction(QIcon(":/icons/edit.svg"), "Edit", bar)
edit_action.setPriority(QAction.Priority.HighPriority)
share_action = QAction(QIcon(":/icons/share.svg"), "Share", bar)
separator = QAction(bar)
separator.setSeparator(True)
sync_action = QAction(QIcon(":/icons/sync.svg"), "Sync", bar)
sync_action.setPriority(QAction.Priority.LowPriority)
pin_action = QAction(QIcon(":/icons/pin.svg"), "Pin", bar)
pin_action.setCheckable(True)
bar.addPrimaryAction(add_action)
bar.addPrimaryAction(edit_action)
bar.addPrimaryAction(share_action)
bar.addPrimaryAction(separator)
bar.addPrimaryAction(sync_action)
bar.addPrimaryAction(pin_action)
bar.addSecondaryAction(
QAction(QIcon(":/icons/settings.svg"), "Settings", bar)
)
bar.addSecondaryAction(
QAction(QIcon(":/icons/help.svg"), "Help", bar)
)
compact_button = fluentqt.Button("Compact view")
labels_button = fluentqt.Button("Labels: Right")
background_button = fluentqt.Button("Show background")
def toggle_compact():
bar_host.setFixedWidth(288 if bar_host.width() > 300 else 536)
def toggle_labels():
collapsed = (
bar.labelPosition()
== fluentqt.CommandBar.LabelPosition.Collapsed
)
bar.setLabelPosition(
fluentqt.CommandBar.LabelPosition.Right
if collapsed
else fluentqt.CommandBar.LabelPosition.Collapsed
)
def toggle_background():
bar.setBackgroundVisible(not bar.backgroundVisible())
compact_button.clicked.connect(toggle_compact)
labels_button.clicked.connect(toggle_labels)
background_button.clicked.connect(toggle_background)
for action in bar.primaryActions() + bar.secondaryActions():
if action.isSeparator():
continue
action.triggered.connect(
lambda checked=False, item=action: fluentqt.Toast.showOrUpdateToast(
bar,
"gallery.action-feedback",
item.text().split(chr(9), 1)[0].replace("&", "") + " selected",
fluentqt.Toast.Informational,
2200,
fluentqt.Toast.Top,
QMargins(16, 50, 16, 16)
)
)API
DeklarationKeine passenden API-Elemente.