本文整理汇总了C++中QMenu::addSection方法的典型用法代码示例。如果您正苦于以下问题:C++ QMenu::addSection方法的具体用法?C++ QMenu::addSection怎么用?C++ QMenu::addSection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMenu
的用法示例。
在下文中一共展示了QMenu::addSection方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setupMenu
void MainWindow::setupMenu()
{
//Setup menu
menuBar = new QMenuBar(centralWidget());
this->setMenuBar(menuBar);
QMenu* fileMenu = new QMenu(tr("File"), menuBar);
QAction *exitAction = new QAction(tr("Exit"), this);
connect(exitAction, &QAction::triggered, this, &MainWindow::close);
fileMenu->addAction(exitAction);
// Profiles
QMenu* profilesMenu = new QMenu(tr("Profiles"));
QAction *backToMainPage = new QAction(tr("Back to main page"), this);
connect(backToMainPage, &QAction::triggered, []() {
SDK::ProfileManager::instance()->backToMainPage();
});
profilesMenu->addAction(backToMainPage);
profilesMenu->addSection(tr("Profiles"));
connect(profilesMenu, &QMenu::triggered, [=](QAction* action) {
SDK::Profile* profile = SDK::ProfileManager::instance()->findById(action->data().toString());
if(profile != NULL)
SDK::ProfileManager::instance()->setActiveProfile(profile);
else
WARN() << qPrintable(QString("Can't load profile %1 from profiles menu!").arg(action->data().toString()));
});
connect(SDK::ProfileManager::instance(), &SDK::ProfileManager::profileChanged, [=](SDK::Profile* profile){
for(QAction* action: profilesMenu->actions())
{
if(action->data().toString() == profile->getId())
{
action->setChecked(true);
profilesMenu->setActiveAction(action);
}
else
{
action->setChecked(false);
}
}
});
for(const SDK::Profile* profile: SDK::ProfileManager::instance()->getProfiles())
{
if(!profile->hasFlag(SDK::Profile::HIDDEN))
{
QAction* loadProfile = new QAction(profile->getName(), profilesMenu);
loadProfile->setData(profile->getId());
loadProfile->setCheckable(true);
loadProfile->setChecked(false);
profilesMenu->addAction(loadProfile);
}
}
// Video menu
QMenu* videoMenu = new QMenu(tr("Video"), menuBar);
QMenu* aspectRatioMenu = new QMenu(tr("Aspect ratio"), videoMenu);
connect(aspectRatioMenu, &QMenu::triggered, [=](QAction* action){
if(player())
player()->setAspectRatio((SDK::AspectRatio) action->data().toInt());
aspectRatioMenu->setActiveAction(action);
for(QAction* a: aspectRatioMenu->actions())
{
a->setChecked(a == action && player());
}
});
connect(aspectRatioMenu, &QMenu::aboutToShow, [=]{
if(!player())
return;
SDK::AspectRatio current_ratio = player()->getAspectRatio();
for(QAction* action: aspectRatioMenu->actions())
{
SDK::AspectRatio ratio = (SDK::AspectRatio) action->data().toInt();
if(ratio == current_ratio)
{
action->setChecked(true);
}
else
{
action->setChecked(false);
}
}
});
QList<QPair<QString, SDK::AspectRatio>> ratios;
ratios.append(QPair<QString, SDK::AspectRatio>(tr("Auto"), SDK::ASPECT_RATIO_AUTO));
ratios.append(QPair<QString, SDK::AspectRatio>(tr("1:1"), SDK::ASPECT_RATIO_1_1));
ratios.append(QPair<QString, SDK::AspectRatio>(tr("5:4"), SDK::ASPECT_RATIO_5_4));
ratios.append(QPair<QString, SDK::AspectRatio>(tr("4:3"), SDK::ASPECT_RATIO_4_3));
//.........这里部分代码省略.........
示例2: contextMenuRequested
void IdealDockWidget::contextMenuRequested(const QPoint &point)
{
QWidget* senderWidget = qobject_cast<QWidget*>(sender());
Q_ASSERT(senderWidget);
QMenu menu;
menu.addSection(windowIcon(), windowTitle());
QList< QAction* > viewActions = m_view->contextMenuActions();
if(!viewActions.isEmpty()) {
menu.addActions(viewActions);
menu.addSeparator();
}
///TODO: can this be cleaned up?
if(QToolBar* toolBar = widget()->findChild<QToolBar*>()) {
menu.addAction(toolBar->toggleViewAction());
menu.addSeparator();
}
/// start position menu
QMenu* positionMenu = menu.addMenu(i18n("Toolview Position"));
QActionGroup *g = new QActionGroup(this);
QAction *left = new QAction(i18nc("toolview position", "Left"), g);
QAction *bottom = new QAction(i18nc("toolview position", "Bottom"), g);
QAction *right = new QAction(i18nc("toolview position", "Right"), g);
QAction *detach = new QAction(i18nc("toolview position", "Detached"), g);
for (auto action : {left, bottom, right, detach}) {
positionMenu->addAction(action);
action->setCheckable(true);
}
if (isFloating()) {
detach->setChecked(true);
} else if (m_docking_area == Qt::BottomDockWidgetArea)
bottom->setChecked(true);
else if (m_docking_area == Qt::LeftDockWidgetArea)
left->setChecked(true);
else if (m_docking_area == Qt::RightDockWidgetArea)
right->setChecked(true);
/// end position menu
menu.addSeparator();
QAction *setShortcut = menu.addAction(QIcon::fromTheme(QStringLiteral("configure-shortcuts")), i18n("Assign Shortcut..."));
setShortcut->setToolTip(i18n("Use this shortcut to trigger visibility of the toolview."));
menu.addSeparator();
QAction* remove = menu.addAction(QIcon::fromTheme(QStringLiteral("dialog-close")), i18n("Remove Toolview"));
QAction* triggered = menu.exec(senderWidget->mapToGlobal(point));
if (triggered)
{
if ( triggered == remove ) {
slotRemove();
return;
} else if ( triggered == setShortcut ) {
QDialog* dialog(new QDialog(this));
dialog->setWindowTitle(i18n("Assign Shortcut For '%1' Tool View", m_view->document()->title()));
KShortcutWidget *w = new KShortcutWidget(dialog);
w->setShortcut(m_controller->actionForView(m_view)->shortcuts());
QVBoxLayout* dialogLayout = new QVBoxLayout(dialog);
dialogLayout->addWidget(w);
QDialogButtonBox* buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
dialogLayout->addWidget(buttonBox);
connect(buttonBox, &QDialogButtonBox::accepted, dialog, &QDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, dialog, &QDialog::reject);
if (dialog->exec() == QDialog::Accepted) {
m_controller->actionForView(m_view)->setShortcuts(w->shortcut());
//save shortcut config
KConfigGroup config = KSharedConfig::openConfig()->group("UI");
QStringList shortcuts;
shortcuts << w->shortcut().value(0).toString();
shortcuts << w->shortcut().value(1).toString();
config.writeEntry(QStringLiteral("Shortcut for %1").arg(m_view->document()->title()), shortcuts);
config.sync();
}
delete dialog;
return;
} else if ( triggered == detach ) {
setFloating(true);
m_area->raiseToolView(m_view);
return;
}
if (isFloating()) {
setFloating(false);
}
Sublime::Position pos;
if (triggered == left)
pos = Sublime::Left;
else if (triggered == bottom)
pos = Sublime::Bottom;
//.........这里部分代码省略.........
示例3: addCodecs
void MainWindow::addCodecs()
{
QMenu *codecMenu;
QActionGroup *codecGroup;
QAction *codecAction;
//Set up Menu and action group
codecMenu = new QMenu(tr("Set Saving Codec"), ui->menuFile);
codecGroup = new QActionGroup(this);
codecGroup->setExclusive(true);
//Add codecs to menu and actionGroup
codecAction = codecMenu->addAction(tr("Ask me (Windows)"));
codecAction->setCheckable(true);
codecGroup->addAction(codecAction);
//Set DIVX Standard
codecAction = codecMenu->addAction("DivX");
codecAction->setCheckable(true);
codecAction->setChecked(true);
setCodec(codecAction);
codecGroup->addAction(codecAction);
codecAction = codecMenu->addAction("FFV1 (FFMPEG Codec)");
codecAction->setCheckable(true);
codecGroup->addAction(codecAction);
codecAction = codecMenu->addAction("HDYC (Raw YUV 4:2:2)");
codecAction->setCheckable(true);
codecGroup->addAction(codecAction);
codecAction = codecMenu->addAction("HEVC (H.265)");
codecAction->setCheckable(true);
codecGroup->addAction(codecAction);
codecAction = codecMenu->addAction("M4S2 (MPEG-4 v2)");
codecAction->setCheckable(true);
codecGroup->addAction(codecAction);
codecAction = codecMenu->addAction("MJPG (Motion JPEG)");
codecAction->setCheckable(true);
codecGroup->addAction(codecAction);
codecAction = codecMenu->addAction("MP2V (MPEG-2)");
codecAction->setCheckable(true);
codecGroup->addAction(codecAction);
codecAction = codecMenu->addAction("MP4V (MPEG-4)");
codecAction->setCheckable(true);
codecGroup->addAction(codecAction);
codecAction = codecMenu->addAction("MPEG (MPEG-1?)");
codecAction->setCheckable(true);
codecGroup->addAction(codecAction);
codecAction = codecMenu->addAction("PIM1 (MPEG-1)");
codecAction->setCheckable(true);
codecGroup->addAction(codecAction);
codecAction = codecMenu->addSection(tr("For Videos"));
codecAction = codecMenu->addAction(tr("Same as Videosource"));
codecAction->setCheckable(true);
codecAction->setChecked(true);
useVideoCodec = true;
//Connect and add to MenuBar
connect(codecMenu, SIGNAL(triggered(QAction*)), this, SLOT(setCodec(QAction*)));
ui->menuFile->insertMenu(ui->actionQuit,codecMenu);
}
示例4: exec
void KateProjectTreeViewContextMenu::exec(const QString &filename, const QPoint &pos, QWidget *parent)
{
/**
* create context menu
*/
QMenu menu;
QAction *copyAction = menu.addAction(QIcon::fromTheme(QStringLiteral("edit-copy")), i18n("Copy Filename"));
/**
* handle "open with"
* find correct mimetype to query for possible applications
*/
QMenu *openWithMenu = menu.addMenu(i18n("Open With"));
QMimeType mimeType = QMimeDatabase().mimeTypeForFile(filename);
KService::List offers = KMimeTypeTrader::self()->query(mimeType.name(), QStringLiteral("Application"));
/**
* for each one, insert a menu item...
*/
for (KService::List::Iterator it = offers.begin(); it != offers.end(); ++it) {
KService::Ptr service = *it;
if (service->name() == QStringLiteral("Kate")) {
continue; // omit Kate
}
QAction *action = openWithMenu->addAction(QIcon::fromTheme(service->icon()), service->name());
action->setData(service->entryPath());
}
/**
* perhaps disable menu, if no entries!
*/
openWithMenu->setEnabled(!openWithMenu->isEmpty());
KMoreToolsMenuFactory menuFactory(QLatin1String("kate/addons/project/git-tools"));
QMenu gitMenu; // must live as long as the maybe filled menu items should live
if (isGit(filename)) {
menuFactory.fillMenuFromGroupingNames(&gitMenu, { QLatin1String("git-clients-and-actions") },
QUrl::fromLocalFile(filename));
menu.addSection(i18n("Git:"));
Q_FOREACH(auto action, gitMenu.actions()) {
menu.addAction(action);
}
}
/**
* run menu and handle the triggered action
*/
if (QAction *action = menu.exec(pos)) {
// handle apps
if (copyAction == action) {
QApplication::clipboard()->setText(filename);
} else {
// handle "open with"
const QString openWith = action->data().toString();
if (KService::Ptr app = KService::serviceByDesktopPath(openWith)) {
QList<QUrl> list;
list << QUrl::fromLocalFile(filename);
KRun::runService(*app, list, parent);
}
}
}
}