菜单与工具栏
CommandPalette 命令面板
输入名称查找并运行命令。
示例

用法
查找并运行命令
addCommand() 注册 QAction;输入关键词后用方向键选择,按 Enter 运行,按 Esc 关闭。
#include <FluentQt/MenusToolbars.h>
using namespace fluent::menus_toolbars;
auto* root = new QWidget(this);
auto* layout = new QVBoxLayout(root);
auto* location = new Label(QStringLiteral("Current page: Home"), root);
location->setObjectName(QStringLiteral("Gallery.CommandPalette.BasicLocation"));
auto* palette = new fluent::menus_toolbars::CommandPalette(root);
palette->setObjectName(QStringLiteral("Gallery.CommandPalette.Basic"));
palette->setPlaceholderText(QStringLiteral("Search pages..."));
const QStringList pages{QStringLiteral("Home"), QStringLiteral("Inbox"),
QStringLiteral("Documents"), QStringLiteral("Folders")};
for (const QString& page : pages) {
auto* action = new QAction(page, root);
palette->addCommand(action, QStringLiteral("Navigation"));
QObject::connect(action, &QAction::triggered, location, [location, page] {
location->setText(QStringLiteral("Current page: %1").arg(page));
});
}
auto* open = new Button(QStringLiteral("Search pages"), root);
open->setObjectName(QStringLiteral("Gallery.CommandPalette.OpenBasic"));
open->setFluentStyle(Button::Accent);
QObject::connect(open, &Button::clicked, palette, &fluent::menus_toolbars::CommandPalette::open);
layout->addWidget(open, 0, Qt::AlignLeft);
layout->addWidget(location);
return root;import fluentqt
from PySide6.QtCore import Qt
from PySide6.QtGui import QAction
from PySide6.QtWidgets import QVBoxLayout
layout = QVBoxLayout(root)
location = fluentqt.Label('Current page: Home')
location.setObjectName('Gallery.CommandPalette.BasicLocation')
palette = fluentqt.CommandPalette(window)
palette.setObjectName('Gallery.CommandPalette.Basic')
palette.setPlaceholderText('Search pages...')
pages = ['Home', 'Inbox', 'Documents', 'Folders']
for page in pages:
action = QAction(page, root)
palette.addCommand(action, "Navigation")
action.triggered.connect(
lambda checked=False, page=page: location.setText(f"Current page: {page}")
)
open_button = fluentqt.Button('Search pages')
open_button.setObjectName('Gallery.CommandPalette.OpenBasic')
open_button.setFluentStyle(fluentqt.Button.ButtonStyle.Accent)
open_button.clicked.connect(palette.open)
layout.addWidget(open_button, 0, Qt.AlignmentFlag.AlignLeft)
layout.addWidget(location)API
查看声明没有匹配的 API 成员。