本文整理汇总了C++中QMenu::x方法的典型用法代码示例。如果您正苦于以下问题:C++ QMenu::x方法的具体用法?C++ QMenu::x怎么用?C++ QMenu::x使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMenu
的用法示例。
在下文中一共展示了QMenu::x方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: showToolBarStylePopupMenu
void PdfViewer::showToolBarStylePopupMenu(const QPoint &pos)
{
QMenu *popupMenu = new QMenu(this);
popupMenu->setAttribute(Qt::WA_DeleteOnClose);
popupMenu->move(mapToGlobal(QPoint(0,0)) + pos);
QWidgetAction *iconOnlyAction = new QWidgetAction(popupMenu);
QRadioButton *iconOnlyRadio = new QRadioButton(tr("&Icons Only"), popupMenu);
iconOnlyAction->setDefaultWidget(iconOnlyRadio);
QWidgetAction *textOnlyAction = new QWidgetAction(popupMenu);
QRadioButton *textOnlyRadio = new QRadioButton(tr("&Text Only"), popupMenu);
textOnlyAction->setDefaultWidget(textOnlyRadio);
QWidgetAction *textBesideIconAction = new QWidgetAction(popupMenu);
QRadioButton *textBesideIconRadio = new QRadioButton(tr("Text &Alongside Icons"), popupMenu);
textBesideIconAction->setDefaultWidget(textBesideIconRadio);
QWidgetAction *textUnderIconAction = new QWidgetAction(popupMenu);
QRadioButton *textUnderIconRadio = new QRadioButton(tr("Text &Under Icons"), popupMenu);
textUnderIconAction->setDefaultWidget(textUnderIconRadio);
QButtonGroup *popupButtonGroup = new QButtonGroup(popupMenu);
popupButtonGroup->addButton(iconOnlyRadio);
popupButtonGroup->addButton(textOnlyRadio);
popupButtonGroup->addButton(textBesideIconRadio);
popupButtonGroup->addButton(textUnderIconRadio);
popupButtonGroup->setId(iconOnlyRadio, 0);
popupButtonGroup->setId(textOnlyRadio, 1);
popupButtonGroup->setId(textBesideIconRadio, 2);
popupButtonGroup->setId(textUnderIconRadio, 3);
connect(popupButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(slotChangeToolBarStyle(int)));
popupMenu->addAction(iconOnlyAction);
popupMenu->addAction(textOnlyAction);
popupMenu->addAction(textBesideIconAction);
popupMenu->addAction(textUnderIconAction);
popupMenu->setContentsMargins(5, 0, 5, 0);
QSettings settings;
settings.beginGroup("MainWindow");
const int toolBarStyleNumber = settings.value("ToolBarStyle", 0).toInt();
switch (toolBarStyleNumber)
{
case 0: iconOnlyRadio->setChecked(true); break;
case 1: textOnlyRadio->setChecked(true); break;
case 2: textBesideIconRadio->setChecked(true); break;
case 3: textUnderIconRadio->setChecked(true); break;
}
settings.endGroup();
popupMenu->show();
// make sure that the popupMenu stays completely inside the screen (must be done after popupMenu->show() in order to have the correct width)
const int desktopWidth = QApplication::desktop()->availableGeometry(this).width();
if (popupMenu->x() + popupMenu->width() > desktopWidth)
popupMenu->move(desktopWidth - popupMenu->width(), popupMenu->y());
}