本文整理汇总了C++中QMenu::setActiveAction方法的典型用法代码示例。如果您正苦于以下问题:C++ QMenu::setActiveAction方法的具体用法?C++ QMenu::setActiveAction怎么用?C++ QMenu::setActiveAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMenu
的用法示例。
在下文中一共展示了QMenu::setActiveAction方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: activeSubMenuPosition
void tst_QMenu::activeSubMenuPosition()
{
QPushButton lab("subMenuPosition test");
QMenu *sub = new QMenu("Submenu", &lab);
sub->addAction("Sub-Item1");
QAction *subAction = sub->addAction("Sub-Item2");
QMenu *main = new QMenu("Menu-Title", &lab);
(void)main->addAction("Item 1");
QAction *menuAction = main->addMenu(sub);
(void)main->addAction("Item 3");
(void)main->addAction("Item 4");
main->setActiveAction(menuAction);
sub->setActiveAction(subAction);
main->popup(QPoint(200,200));
QVERIFY(main->isVisible());
QCOMPARE(main->activeAction(), menuAction);
QVERIFY(sub->isVisible());
QVERIFY(sub->pos() != QPoint(0,0));
// well, it's enough to check the pos is not (0,0) but it's more safe
// to check that submenu is to the right of the main menu too.
#ifndef Q_OS_WINCE_WM
QVERIFY(sub->pos().x() > main->pos().x());
QCOMPARE(sub->activeAction(), subAction);
#endif
}
示例2: selectPropertyButtonClicked
void CaptionGraphicsItem::selectPropertyButtonClicked() {
if (_view->graph() == nullptr)
return;
QMenu menu;
for (const string &piName : _view->graph()->getProperties()) {
if (_view->graph()->getProperty(piName)->getTypename() != "double")
continue;
QAction *action = menu.addAction(piName.c_str(), this, SLOT(propertySelectedSlot()));
if (_confPropertySelectionWidget->text() == QString(piName.c_str()))
menu.setActiveAction(action);
}
// set a combo like stylesheet
QPalette palette = QComboBox().palette();
menu.setStyleSheet(QString("QMenu::item {color: %1; background-color: %2;} QMenu::item:selected "
"{color: %3; background-color: %4}")
.arg(palette.color(QPalette::Active, QPalette::Text).name())
.arg(palette.color(QPalette::Active, QPalette::Base).name())
.arg(palette.color(QPalette::Active, QPalette::HighlightedText).name())
.arg(palette.color(QPalette::Active, QPalette::Highlight).name()));
// compute a combo like position
// to popup the menu
QWidget *pViewport = QApplication::widgetAt(QCursor::pos());
QWidget *pView = pViewport->parentWidget();
QGraphicsView *pGraphicsView = qobject_cast<QGraphicsView *>(pView);
QPoint popupPos =
pGraphicsView->mapToGlobal(pGraphicsView->mapFromScene(_confPropertySelectionItem->mapToScene(
_confPropertySelectionItem->subWidgetRect(_confPropertySelectionWidget).bottomLeft())));
menu.exec(popupPos);
}
示例3: insert
void TermLabel::insert()
{
GlossaryNS::Glossary* glossary=Project::instance()->glossary();
if (m_entryId.isEmpty())
return;
QString termTrans;
const QStringList& termTarget=glossary->terms(m_entryId, Project::instance()->targetLangCode());
if( termTarget.count()>1)
{
QMenu menu;
int limit=termTarget.count();
menu.setActiveAction(menu.addAction(termTarget.at(0)));
int i=1;
for (;i<limit;++i)
menu.addAction(termTarget.at(i));
QAction* txt=menu.exec(mapToGlobal(QPoint(0,0)));
if (!txt)
return;
termTrans=txt->text();
}
else
termTrans=termTarget.first();
if (m_capFirst && !termTrans.isEmpty())
termTrans[0]=termTrans.at(0).toUpper();
emit insertTerm(termTrans);
}
示例4: fillSenderIdentities
void MailFieldsWidget::fillSenderIdentities()
{
QMenu* menu = new QMenu(this);
ui->fromButton->setMenu(menu);
QAction* first = nullptr;
auto profile = bts::application::instance()->get_profile();
std::vector<bts::addressbook::wallet_identity> identities = profile->identities();
for(const auto& identity : identities)
{
std::string entry = identity.get_display_name();
auto ipk = identity.public_key;
assert(ipk.valid());
QAction* action = menu->addAction(tr(entry.c_str()));
action->setCheckable(true);
Action2Identity.insert(TAction2IdentityIndex::value_type(action, identity));
if(first == nullptr)
first = action;
}
connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(onFromBtnTriggered(QAction*)));
onFromBtnTriggered(first);
menu->setActiveAction(first);
}
示例5: fillSenderIdentities
void MailFieldsWidget::fillSenderIdentities()
{
QMenu* menu = new QMenu(this);
ui->fromButton->setMenu(menu);
QAction* first = nullptr;
std::vector<bts::addressbook::wallet_identity> identities = bts::application::instance()->get_profile()->identities();
for(const auto& identity : identities)
{
std::string identity_label = identity.first_name + " " + identity.last_name;
std::string entry(identity_label);
if(identity_label.empty() == false)
entry += '(';
entry += identity.dac_id_string;
if(identity_label.empty() == false)
entry += ')';
QAction* action = menu->addAction(tr(entry.c_str()));
action->setCheckable(true);
Action2Identity.insert(TAction2IdentityIndex::value_type(action, identity));
if(first == nullptr)
first = action;
}
connect(menu, SIGNAL(triggered(QAction*)), this, SLOT(onFromBtnTriggered(QAction*)));
onFromBtnTriggered(first);
menu->setActiveAction(first);
}
示例6: activeSubMenuPosition
void tst_QMenu::activeSubMenuPosition()
{
QPushButton lab("subMenuPosition test");
QMenu *sub = new QMenu("Submenu", &lab);
sub->addAction("Sub-Item1");
QAction *subAction = sub->addAction("Sub-Item2");
QMenu *main = new QMenu("Menu-Title", &lab);
(void)main->addAction("Item 1");
QAction *menuAction = main->addMenu(sub);
(void)main->addAction("Item 3");
(void)main->addAction("Item 4");
main->setActiveAction(menuAction);
sub->setActiveAction(subAction);
#ifdef Q_OS_SYMBIAN
main->popup(QPoint(50,200));
#else
main->popup(QPoint(200,200));
#endif
QVERIFY(main->isVisible());
QCOMPARE(main->activeAction(), menuAction);
QVERIFY(sub->isVisible());
QVERIFY(sub->pos() != QPoint(0,0));
// well, it's enough to check the pos is not (0,0) but it's more safe
// to check that submenu is to the right of the main menu too.
#ifdef Q_OS_WINCE_WM
QSKIP("Not true for Windows Mobile Soft Keys", SkipSingle);
#endif
#ifdef Q_OS_SYMBIAN
// On Symbian, QS60Style::pixelMetric(QStyle::PM_SubMenuOverlap) is different with other styles.
QVERIFY(sub->pos().x() < main->pos().x());
#else
QVERIFY(sub->pos().x() > main->pos().x());
#endif
QCOMPARE(sub->activeAction(), subAction);
}
示例7: widgetActionFocus
void tst_QMenu::widgetActionFocus()
{
//test if the focus is correctly handled with a QWidgetAction
QMenu m;
QListWidget *l = new QListWidget(&m);
for (int i = 1; i<3 ; i++)
l->addItem(QString("item%1").arg(i));
QWidgetAction *wa = new QWidgetAction(&m);
wa->setDefaultWidget(l);
m.addAction(wa);
m.setActiveAction(wa);
l->setFocus(); //to ensure it has primarily the focus
QAction *menuitem1=m.addAction("menuitem1");
QAction *menuitem2=m.addAction("menuitem2");
m.popup(QPoint());
QVERIFY(m.isVisible());
QVERIFY(l->hasFocus());
QVERIFY(l->currentItem());
QCOMPARE(l->currentItem()->text(), QString("item1"));
QTest::keyClick(QApplication::focusWidget(), Qt::Key_Down);
QVERIFY(l->currentItem());
QCOMPARE(l->currentItem()->text(), QString("item2"));
QTest::keyClick(QApplication::focusWidget(), Qt::Key_Down);
QVERIFY(m.hasFocus());
QCOMPARE(m.activeAction(), menuitem1);
QTest::keyClick(QApplication::focusWidget(), Qt::Key_Down);
QVERIFY(m.hasFocus());
QCOMPARE(m.activeAction(), menuitem2);
QTest::keyClick(QApplication::focusWidget(), Qt::Key_Up);
QVERIFY(m.hasFocus());
QCOMPARE(m.activeAction(), menuitem1);
QTest::keyClick(QApplication::focusWidget(), Qt::Key_Up);
QVERIFY(l->hasFocus());
QCOMPARE(m.activeAction(), (QAction *)wa);
}
示例8: on_treeBook_customContextMenuRequested
/// Context menu for tree.
void VondelWindow::on_treeBook_customContextMenuRequested(QPoint pos)
{
QMenu *menu = new QMenu;
QTreeWidgetItem *item = ui->treeBook->itemAt(pos.x(), pos.y());
int id = item->type() - QTreeWidgetItem::UserType;
if (id >= 2000) {
id -= 1999; // Scene selected.
//VondelScene *scene = vondelBook.getScene(id);
menu->addAction(tr("Scene"));
menu->addAction(ui->action_Add_New_Scene);
menu->setActiveAction(ui->action_Add_New_Scene);
} else if (id >= 1000) {
id -=999; // Chapter selected.
menu->addAction(ui->action_Add_New_Scene);
menu->addAction(ui->action_Add_New_Chapter);
} else { // Book selected.
menu->addAction(ui->action_Add_New_Chapter);
menu->addAction(ui->action_Add_New_Character);
}
menu->exec(QCursor::pos());
}
示例9: mouseReleaseEvent
void KxMenuItemWidget::mouseReleaseEvent(QMouseEvent * event)
{
bool triggerOptionBoxAction = false;
Qt::KeyboardModifiers mods = event->modifiers();
bool optionBoxModifier = (mods == Qt::ShiftModifier);
bool saveToShelfModifier = (mods == (Qt::ShiftModifier|Qt::ControlModifier));
if(!fMenuItem->isSeparator() && fMenuItem->isEnabled()) {
if(fMenuItem->hasOptionBox()) {
QRect boxRect;
QWidget *q = parentWidget();
const int hmargin = q->style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, q),
iconWidth = q->style()->pixelMetric(QStyle::PM_SmallIconSize, 0, q);
boxRect.setRect(rect().right() - hmargin - iconWidth, rect().top(), iconWidth, rect().height());
if(boxRect.contains(event->pos()) || optionBoxModifier) {
triggerOptionBoxAction = true;
QMenu *menu = qobject_cast<QMenu *>(parentWidget());
if(menu && !saveToShelfModifier) {
menu->setActiveAction(NULL);
}
}
}
}
if(saveToShelfModifier) {
if(fMenuItem->saveToShelf(triggerOptionBoxAction ? KxMenuItem::kOptionBoxAction : KxMenuItem::kMainAction)) {
return;
}
}
QWidget::mouseReleaseEvent(event);
if(triggerOptionBoxAction) {
fMenuItem->optionBoxAction()->activate(QAction::Trigger);
}
}
示例10: img
IconFactory::IconFactory()
: m_iconColor()
, m_iconColorActive()
, m_useSystemIcons(true)
, m_loaded(false)
, m_iconCache()
, m_resourceIconCache()
{
m_loaded = QFontDatabase::addApplicationFont(":/images/fontawesome-webfont.ttf") != -1;
// Try to get menu color more precisely by rendering dummy widget and getting color of pixel
// that is presumably menu background.
QMenu menu;
QImage img(1, 1, QImage::Format_RGB32);
menu.resize(16, 16);
menu.render(&img, QPoint(-8, -8));
m_iconColor = getDefaultIconColor( img.pixel(0, 0) );
menu.setActiveAction( menu.addAction(QString()) );
menu.render(&img, QPoint(-8, -8));
m_iconColorActive = getDefaultIconColor( img.pixel(0, 0) );
}
示例11: 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));
//.........这里部分代码省略.........
示例12: setActiveAction
void QMenuProto::setActiveAction(QAction *act)
{
QMenu *item = qscriptvalue_cast<QMenu*>(thisObject());
if (item)
item->setActiveAction(act);
}