本文整理汇总了C++中QMenuBar::setContextMenuPolicy方法的典型用法代码示例。如果您正苦于以下问题:C++ QMenuBar::setContextMenuPolicy方法的具体用法?C++ QMenuBar::setContextMenuPolicy怎么用?C++ QMenuBar::setContextMenuPolicy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMenuBar
的用法示例。
在下文中一共展示了QMenuBar::setContextMenuPolicy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PostWindowCreate
void QmitkExtWorkbenchWindowAdvisor::PostWindowCreate()
{
QmitkCommonWorkbenchWindowAdvisor::PostWindowCreate();
// very bad hack...
berry::IWorkbenchWindow::Pointer window =
this->GetWindowConfigurer()->GetWindow();
QMainWindow* mainWindow =
static_cast<QMainWindow*> (window->GetShell()->GetControl());
if (!windowIcon.empty())
{
mainWindow->setWindowIcon(QIcon(QString::fromStdString(windowIcon)));
}
mainWindow->setContextMenuPolicy(Qt::PreventContextMenu);
/*mainWindow->setStyleSheet("color: white;"
"background-color: #808080;"
"selection-color: #659EC7;"
"selection-background-color: #808080;"
" QMenuBar {"
"background-color: #808080; }");*/
// ==== Application menu ============================
QMenuBar* menuBar = mainWindow->menuBar();
menuBar->setContextMenuPolicy(Qt::PreventContextMenu);
QMenu* fileMenu = menuBar->addMenu("&File");
fileMenu->setObjectName("FileMenu");
QAction* fileOpenAction = new QmitkExtFileOpenAction(QIcon(":/org.mitk.gui.qt.ext/Load_48.png"), window);
fileMenu->addAction(fileOpenAction);
fileSaveProjectAction = new QmitkExtFileSaveProjectAction(window);
fileSaveProjectAction->setIcon(QIcon(":/org.mitk.gui.qt.ext/Save_48.png"));
fileMenu->addAction(fileSaveProjectAction);
closeProjectAction = new QmitkCloseProjectAction(window);
closeProjectAction->setIcon(QIcon(":/org.mitk.gui.qt.ext/Remove_48.png"));
fileMenu->addAction(closeProjectAction);
fileMenu->addSeparator();
QAction* fileExitAction = new QmitkFileExitAction(window);
fileExitAction->setObjectName("QmitkFileExitAction");
fileMenu->addAction(fileExitAction);
berry::IViewRegistry* viewRegistry =
berry::PlatformUI::GetWorkbench()->GetViewRegistry();
const std::vector<berry::IViewDescriptor::Pointer>& viewDescriptors =
viewRegistry->GetViews();
// another bad hack to get an edit/undo menu...
QMenu* editMenu = menuBar->addMenu("&Edit");
undoAction = editMenu->addAction(QIcon(":/org.mitk.gui.qt.ext/Undo_48.png"),
"&Undo",
QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onUndo()),
QKeySequence("CTRL+Z"));
undoAction->setToolTip("Undo the last action (not supported by all modules)");
redoAction = editMenu->addAction(QIcon(":/org.mitk.gui.qt.ext/Redo_48.png")
, "&Redo",
QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onRedo()),
QKeySequence("CTRL+Y"));
redoAction->setToolTip("execute the last action that was undone again (not supported by all modules)");
imageNavigatorAction = new QAction(QIcon(":/org.mitk.gui.qt.ext/Slider.png"), "&Image Navigator", NULL);
bool imageNavigatorViewFound = window->GetWorkbench()->GetViewRegistry()->Find("org.mitk.views.imagenavigator");
if (imageNavigatorViewFound)
{
QObject::connect(imageNavigatorAction, SIGNAL(triggered(bool)), QmitkExtWorkbenchWindowAdvisorHack::undohack, SLOT(onImageNavigator()));
imageNavigatorAction->setCheckable(true);
// add part listener for image navigator
imageNavigatorPartListener = new PartListenerForImageNavigator(imageNavigatorAction);
window->GetPartService()->AddPartListener(imageNavigatorPartListener);
berry::IViewPart::Pointer imageNavigatorView =
window->GetActivePage()->FindView("org.mitk.views.imagenavigator");
imageNavigatorAction->setChecked(false);
if (imageNavigatorView)
{
bool isImageNavigatorVisible = window->GetActivePage()->IsPartVisible(imageNavigatorView);
if (isImageNavigatorVisible)
imageNavigatorAction->setChecked(true);
}
imageNavigatorAction->setToolTip("Open image navigator for navigating through image");
}
// toolbar for showing file open, undo, redo and other main actions
QToolBar* mainActionsToolBar = new QToolBar;
mainActionsToolBar->setContextMenuPolicy(Qt::PreventContextMenu);
#ifdef __APPLE__
mainActionsToolBar->setToolButtonStyle ( Qt::ToolButtonTextUnderIcon );
#else
mainActionsToolBar->setToolButtonStyle ( Qt::ToolButtonTextBesideIcon );
#endif
mainActionsToolBar->addAction(fileOpenAction);
mainActionsToolBar->addAction(fileSaveProjectAction);
mainActionsToolBar->addAction(closeProjectAction);
mainActionsToolBar->addAction(undoAction);
mainActionsToolBar->addAction(redoAction);
if (imageNavigatorViewFound)
{
mainActionsToolBar->addAction(imageNavigatorAction);
}
//.........这里部分代码省略.........
示例2: PostWindowCreate
void QmitkExtWorkbenchWindowAdvisor::PostWindowCreate()
{
// very bad hack...
berry::IWorkbenchWindow::Pointer window =
this->GetWindowConfigurer()->GetWindow();
QMainWindow* mainWindow =
qobject_cast<QMainWindow*> (window->GetShell()->GetControl());
if (!windowIcon.isEmpty())
{
mainWindow->setWindowIcon(QIcon(windowIcon));
}
mainWindow->setContextMenuPolicy(Qt::PreventContextMenu);
/*mainWindow->setStyleSheet("color: white;"
"background-color: #808080;"
"selection-color: #659EC7;"
"selection-background-color: #808080;"
" QMenuBar {"
"background-color: #808080; }");*/
// Load selected icon theme
QStringList searchPaths = QIcon::themeSearchPaths();
searchPaths.push_front( QString(":/org_mitk_icons/icons/") );
QIcon::setThemeSearchPaths( searchPaths );
berry::IPreferencesService* prefService = berry::Platform::GetPreferencesService();
berry::IPreferences::Pointer stylePref = prefService->GetSystemPreferences()->Node(berry::QtPreferences::QT_STYLES_NODE);
QString iconTheme = stylePref->Get(berry::QtPreferences::QT_ICON_THEME, "<<default>>");
if( iconTheme == QString( "<<default>>" ) )
{
iconTheme = QString( "tango" );
}
QIcon::setThemeName( iconTheme );
// ==== Application menu ============================
QMenuBar* menuBar = mainWindow->menuBar();
menuBar->setContextMenuPolicy(Qt::PreventContextMenu);
#ifdef __APPLE__
menuBar->setNativeMenuBar(true);
#else
menuBar->setNativeMenuBar(false);
#endif
QAction* fileOpenAction = new QmitkFileOpenAction(QIcon::fromTheme("document-open",QIcon(":/org_mitk_icons/icons/tango/scalable/actions/document-open.svg")), window);
fileOpenAction->setShortcut(QKeySequence::Open);
QAction* fileSaveAction = new QmitkFileSaveAction(QIcon(":/org.mitk.gui.qt.ext/Save_48.png"), window);
fileSaveAction->setShortcut(QKeySequence::Save);
fileSaveProjectAction = new QmitkExtFileSaveProjectAction(window);
fileSaveProjectAction->setIcon(QIcon::fromTheme("document-save",QIcon(":/org_mitk_icons/icons/tango/scalable/actions/document-save.svg")));
closeProjectAction = new QmitkCloseProjectAction(window);
closeProjectAction->setIcon(QIcon::fromTheme("edit-delete",QIcon(":/org_mitk_icons/icons/tango/scalable/actions/edit-delete.svg")));
auto perspGroup = new QActionGroup(menuBar);
std::map<QString, berry::IViewDescriptor::Pointer> VDMap;
// sort elements (converting vector to map...)
QList<berry::IViewDescriptor::Pointer>::const_iterator iter;
berry::IViewRegistry* viewRegistry =
berry::PlatformUI::GetWorkbench()->GetViewRegistry();
const QList<berry::IViewDescriptor::Pointer> viewDescriptors = viewRegistry->GetViews();
bool skip = false;
for (iter = viewDescriptors.begin(); iter != viewDescriptors.end(); ++iter)
{
// if viewExcludeList is set, it contains the id-strings of view, which
// should not appear as an menu-entry in the menu
if (viewExcludeList.size() > 0)
{
for (int i=0; i<viewExcludeList.size(); i++)
{
if (viewExcludeList.at(i) == (*iter)->GetId())
{
skip = true;
break;
}
}
if (skip)
{
skip = false;
continue;
}
}
if ((*iter)->GetId() == "org.blueberry.ui.internal.introview")
continue;
if ((*iter)->GetId() == "org.mitk.views.imagenavigator")
continue;
if ((*iter)->GetId() == "org.mitk.views.viewnavigatorview")
continue;
std::pair<QString, berry::IViewDescriptor::Pointer> p(
(*iter)->GetLabel(), (*iter));
VDMap.insert(p);
}
//.........这里部分代码省略.........