本文整理汇总了C++中QMenu::isEnabled方法的典型用法代码示例。如果您正苦于以下问题:C++ QMenu::isEnabled方法的具体用法?C++ QMenu::isEnabled怎么用?C++ QMenu::isEnabled使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMenu
的用法示例。
在下文中一共展示了QMenu::isEnabled方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isEnabled
bool isEnabled() const
{
return menu ? menu->isEnabled() : menuBar->isEnabled();
}
示例2: contextMenuEvent
void HeaderViewWidget::contextMenuEvent(QContextMenuEvent *event)
{
ItemViewWidget *view = qobject_cast<ItemViewWidget*>(parent());
if (!view)
{
return;
}
const int sortColumn = view->getSortColumn();
const int sortOrder = view->getSortOrder();
QMenu menu(this);
QMenu *sortMenu = menu.addMenu(tr("Sorting"));
QAction *sortAscendingAction = sortMenu->addAction(tr("Sort Ascending"));
sortAscendingAction->setData(-2);
sortAscendingAction->setCheckable(true);
sortAscendingAction->setChecked(sortOrder == Qt::AscendingOrder);
QAction *sortDescendingAction = sortMenu->addAction(tr("Sort Descending"));
sortDescendingAction->setData(-3);
sortDescendingAction->setCheckable(true);
sortDescendingAction->setChecked(sortOrder == Qt::DescendingOrder);
sortMenu->addSeparator();
QAction *noSortAction = sortMenu->addAction(tr("No Sorting"));
noSortAction->setData(-1);
noSortAction->setCheckable(true);
noSortAction->setChecked(sortColumn < 0);
sortMenu->addSeparator();
QMenu *visibilityMenu = menu.addMenu(tr("Visible Columns"));
visibilityMenu->setEnabled(model()->columnCount() > 1);
QAction *showAllColumnsAction = NULL;
bool allColumnsVisible = true;
if (visibilityMenu->isEnabled())
{
showAllColumnsAction = visibilityMenu->addAction(tr("Show All"));
showAllColumnsAction->setData(-1);
showAllColumnsAction->setCheckable(true);
visibilityMenu->addSeparator();
}
for (int i = 0; i < model()->columnCount(); ++i)
{
const QString title(model()->headerData(i, orientation()).toString());
QAction *action = sortMenu->addAction(title);
action->setData(i);
action->setCheckable(true);
action->setChecked(i == sortColumn);
if (visibilityMenu->isEnabled())
{
QAction *action = visibilityMenu->addAction(title);
action->setData(i);
action->setCheckable(true);
action->setChecked(!view->isColumnHidden(i));
if (!action->isChecked())
{
allColumnsVisible = false;
}
}
}
if (showAllColumnsAction)
{
showAllColumnsAction->setChecked(allColumnsVisible);
showAllColumnsAction->setEnabled(!allColumnsVisible);
}
connect(sortMenu, SIGNAL(triggered(QAction*)), this, SLOT(toggleSort(QAction*)));
connect(visibilityMenu, SIGNAL(triggered(QAction*)), this, SLOT(toggleColumnVisibility(QAction*)));
menu.exec(event->globalPos());
}