本文整理汇总了C++中QMenuBar::removeAction方法的典型用法代码示例。如果您正苦于以下问题:C++ QMenuBar::removeAction方法的具体用法?C++ QMenuBar::removeAction怎么用?C++ QMenuBar::removeAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMenuBar
的用法示例。
在下文中一共展示了QMenuBar::removeAction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setup
void MenuManager::setup(MenuItem* menuItems) const
{
if (!menuItems)
return; // empty menu bar
QMenuBar* menuBar = getMainWindow()->menuBar();
//menuBar->setUpdatesEnabled(false);
QList<MenuItem*> items = menuItems->getItems();
QList<QAction*> actions = menuBar->actions();
for (QList<MenuItem*>::ConstIterator it = items.begin(); it != items.end(); ++it)
{
// search for the menu action
QAction* action = findAction(actions, QString::fromAscii((*it)->command().c_str()));
if (!action) {
// There must be not more than one separator in the menu bar, so
// we can safely remove it if available and append it at the end
if ((*it)->command() == "Separator") {
action = menuBar->addSeparator();
action->setObjectName(QLatin1String("Separator"));
}
else {
// create a new menu
std::string menuName = (*it)->command();
QMenu* menu = menuBar->addMenu(
QApplication::translate("Workbench", menuName.c_str(),
0, QApplication::UnicodeUTF8));
action = menu->menuAction();
menu->setObjectName(QString::fromAscii(menuName.c_str()));
action->setObjectName(QString::fromAscii(menuName.c_str()));
}
// set the menu user data
action->setData(QString::fromAscii((*it)->command().c_str()));
}
else {
// put the menu at the end
menuBar->removeAction(action);
menuBar->addAction(action);
action->setVisible(true);
int index = actions.indexOf(action);
actions.removeAt(index);
}
// flll up the menu
if (!action->isSeparator())
setup(*it, action->menu());
}
// hide all menus which we don't need for the moment
for (QList<QAction*>::Iterator it = actions.begin(); it != actions.end(); ++it) {
(*it)->setVisible(false);
}
// enable update again
//menuBar->setUpdatesEnabled(true);
}
示例2: removeAction
void removeAction(QAction* action)
{
menu ? menu->removeAction(action) : menuBar->removeAction(action);
}