本文整理汇总了C++中QAction::menu方法的典型用法代码示例。如果您正苦于以下问题:C++ QAction::menu方法的具体用法?C++ QAction::menu怎么用?C++ QAction::menu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAction
的用法示例。
在下文中一共展示了QAction::menu方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: paintEvent
void QDesignerMenuBar::paintEvent(QPaintEvent *event)
{
QMenuBar::paintEvent(event);
QPainter p(this);
foreach (QAction *a, actions()) {
if (qobject_cast<SpecialMenuAction*>(a)) {
const QRect g = actionGeometry(a);
QLinearGradient lg(g.left(), g.top(), g.left(), g.bottom());
lg.setColorAt(0.0, Qt::transparent);
lg.setColorAt(0.7, QColor(0, 0, 0, 32));
lg.setColorAt(1.0, Qt::transparent);
p.fillRect(g, lg);
}
}
QAction *action = currentAction();
if (m_dragging || !action)
return;
if (hasFocus()) {
const QRect g = actionGeometry(action);
QDesignerMenu::drawSelection(&p, g.adjusted(1, 1, -1, -1));
} else if (action->menu() && action->menu()->isVisible()) {
const QRect g = actionGeometry(action);
p.drawRect(g.adjusted(1, 1, -1, -1));
}
}
示例2: manageMenuBar
void AcceleratorManagerPrivate::manageMenuBar(QMenuBar *mbar, Item *item)
{
QAction *maction;
QString s;
for (int i=0; i<mbar->actions().count(); ++i)
{
maction = mbar->actions()[i];
if (!maction)
continue;
// nothing to do for separators
if (maction->isSeparator())
continue;
s = maction->text();
if (!s.isEmpty())
{
Item *it = new Item;
item->addChild(it);
it->m_content =
AccelString(s,
// menu titles are important, so raise the weight
AccelManagerAlgorithm::MENU_TITLE_WEIGHT);
it->m_widget = mbar;
it->m_index = i;
}
// have a look at the popup as well, if present
if (maction->menu())
PopupAccelManager::manage(maction->menu());
}
}
示例3: updateBookmarks
void MainWindow::updateBookmarks(int folder)
{
if (m_ui->menuBookmarks->actions().count() == 3)
{
return;
}
for (int i = (m_ui->menuBookmarks->actions().count() - 1); i > 2; --i)
{
QAction *action = m_ui->menuBookmarks->actions().at(i);
if (folder == 0)
{
action->deleteLater();
m_ui->menuBookmarks->removeAction(action);
}
else if (m_ui->menuBookmarks->actions().at(i)->menu())
{
action->menu()->deleteLater();
action->setMenu(new QMenu());
connect(action->menu(), SIGNAL(aboutToShow()), this, SLOT(menuBookmarksAboutToShow()));
}
}
}
示例4: mouseReleaseEvent
void Menu::mouseReleaseEvent(QMouseEvent* e)
{
QAction* qact = actionAt(e->pos());
Action* act = qobject_cast<Action*> (qact);
if (qact && qact->menu()) {
Menu* m = qobject_cast<Menu*> (qact->menu());
if (!m) {
QMenu::mouseReleaseEvent(e);
return;
}
if (e->button() == Qt::MiddleButton || (e->button() == Qt::LeftButton && e->modifiers() == Qt::ControlModifier)) {
closeAllMenus();
emit menuMiddleClicked(m);
}
}
if (!act) {
QMenu::mouseReleaseEvent(e);
return;
}
if (e->button() == Qt::LeftButton && e->modifiers() == Qt::NoModifier) {
closeAllMenus();
act->trigger();
e->accept();
}
else if (e->button() == Qt::MiddleButton || (e->button() == Qt::LeftButton && e->modifiers() == Qt::ControlModifier)) {
closeAllMenus();
act->triggerMiddleClick();
e->accept();
}
}
示例5: containsMenu
bool WidgetMenuBarMapEditor::containsMenu() const {
QAction * action = this->activeAction();
if (action != nullptr && action->menu() != nullptr) {
return action->menu()->rect().contains(action->menu()->mapFromGlobal(
QCursor::pos()));
}
return false;
}
示例6: showMenu
/* private slots */
void ViewerToolBar::showMenu()
{
QAction *act = static_cast<QAction*>(sender());
if ( act->menu()->isVisible() ) act->menu()->hide();
else {
act->menu()->show();
act->menu()->move(QCursor::pos());
};
}
示例7: showHoveredMenu
void ToolBar::showHoveredMenu()
{
QAction *act = static_cast<QAction*>(sender());
if ( act==itemControlAction ) {
act->menu()->show();
act->menu()->move(QCursor::pos());
} else {
if ( itemControlAction->menu()->isVisible() )
itemControlAction->menu()->hide();
}
}
示例8: data
QVariant pActionsModel::data( const QModelIndex& index, int role ) const
{
QAction* action = this->action( index );
if ( !action ) {
return QVariant();
}
switch ( role ) {
case Qt::DecorationRole:
switch ( index.column() ) {
case 0:
return action->icon();
default:
break;
}
break;
case Qt::DisplayRole:
case Qt::ToolTipRole:
switch ( index.column() ) {
case pActionsModel::Action:
return cleanText( action->text() );
case pActionsModel::Shortcut:
return action->shortcut().toString( QKeySequence::NativeText );
case pActionsModel::DefaultShortcut:
return defaultShortcut( action ).toString( QKeySequence::NativeText );
}
break;
case Qt::FontRole: {
QFont font = action->font();
if ( action->menu() ) {
font.setBold( true );
}
return font;
}
/*case Qt::BackgroundRole:
return action->menu() ? QBrush( QColor( 0, 0, 255, 20 ) ) : QVariant();*/
case pActionsModel::MenuRole:
return QVariant::fromValue( action->menu() );
case pActionsModel::ActionRole:
return QVariant::fromValue( action );
}
return QVariant();
}
示例9: while
QMenu *VerticalMenu::leafMenu()
{
QMenu *leaf = this;
while (true) {
QAction *act = leaf->activeAction();
if (act && act->menu() && act->menu()->isVisible()) {
leaf = act->menu();
continue;
}
return leaf == this ? 0 : leaf;
}
return 0; // make gcc happy
}
示例10: qt_wce_get_quit_action
//search for first QuitRole in QMenuBar
static QAction* qt_wce_get_quit_action(QList<QAction *> actionItems)
{
QAction *returnAction = 0;
for (int i = 0; i < actionItems.size(); ++i) {
QAction *action = actionItems.at(i);
if (action->menuRole() == QAction::QuitRole)
returnAction = action;
else if (action->menu())
returnAction = qt_wce_get_quit_action(action->menu()->actions());
if (returnAction)
return returnAction; //return first action found
}
return 0; //nothing found;
}
示例11: mouseReleaseEvent
void PopupMenu::mouseReleaseEvent(QMouseEvent *e)
{
DEBUG_PRST_ROUTES(stderr, "PopupMenu::mouseReleaseEvent this:%p\n", this);
if(_contextMenu && _contextMenu->isVisible())
return;
// Removed by Tim. Why not stay-open scrollable menus?
// if(MusEGlobal::config.scrollableSubMenus)
// {
// QMenu::mouseReleaseEvent(e);
// return;
// }
QAction* action = actionAt(e->pos());
if (!(action && action == activeAction() && !action->isSeparator() && action->isEnabled()))
action=NULL;
#ifdef POPUP_MENU_DISABLE_STAY_OPEN
if (action && action->menu() != NULL && action->isCheckable())
action->activate(QAction::Trigger);
QMenu::mouseReleaseEvent(e);
if (action && action->menu() != NULL && action->isCheckable())
close();
return;
#else
// Check for Ctrl to stay open.
const bool stay_open = _stayOpen && (MusEGlobal::config.popupsDefaultStayOpen || (e->modifiers() & Qt::ControlModifier));
// Stay open? Or does the action have a submenu, but also a checkbox of its own?
if(action && (stay_open || (action->isEnabled() && action->menu() && action->isCheckable())))
{
DEBUG_PRST_ROUTES(stderr, "PopupMenu::mouseReleaseEvent: stay open\n");
action->trigger(); // Trigger the action.
e->accept();
if(!stay_open)
closeUp();
return; // We handled it.
}
// Otherwise let ancestor QMenu handle it...
e->ignore();
QMenu::mouseReleaseEvent(e);
#endif // POPUP_MENU_DISABLE_STAY_OPEN
}
示例12:
QMenu *QActionProto::menu() const
{
QAction *item = qscriptvalue_cast<QAction*>(thisObject());
if (item)
return item->menu();
return 0;
}
示例13: event
// taken from libqtxdg: XdgMenuWidget
bool XdgCachedMenu::event(QEvent* event)
{
if (event->type() == QEvent::MouseButtonPress)
{
QMouseEvent *e = static_cast<QMouseEvent*>(event);
if (e->button() == Qt::LeftButton)
mDragStartPosition = e->pos();
}
else if (event->type() == QEvent::MouseMove)
{
QMouseEvent *e = static_cast<QMouseEvent*>(event);
handleMouseMoveEvent(e);
}
else if(event->type() == QEvent::ToolTip)
{
QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event);
QAction* action = actionAt(helpEvent->pos());
if(action && action->menu() == NULL)
QToolTip::showText(helpEvent->globalPos(), action->toolTip(), this);
}
return QMenu::event(event);
}
示例14: dropEvent
void MenuBar::dropEvent(QDropEvent *event)
{
const MimeDataObject *mimeData = qobject_cast<const MimeDataObject *>(event->mimeData());
QAction *aAction = qobject_cast<QAction *>(mimeData->object());
if (aAction && isEdited()) {
if (activeAction())
if (activeAction()->menu())
activeAction()->menu()->close();
if (aAction->menu())
if (aAction->objectName() == "actionNewMenu") {
Menu *menu = new Menu(aAction->text());
menu->setEdited(true);
aAction = menu->menuAction();
}
QAction *eAction = this->actionAt(event->pos());
QRect rect = actionGeometry(eAction);
eAction = this->actionAt(QPoint(event->pos().x()+rect.width()/2,
event->pos().y()));
if (eAction) {
if (aAction->isSeparator())
insertSeparator(eAction);
else
insertAction(eAction,aAction);
} else {
if (aAction->isSeparator())
addSeparator();
else
addAction(aAction);
}
event->acceptProposedAction();
}
}
示例15: updateCurrentAction
void QDesignerMenuBar::updateCurrentAction(bool selectAction)
{
update();
if (!selectAction)
return;
QAction *action = currentAction();
if (!action || action == m_addMenu)
return;
QMenu *menu = action->menu();
if (!menu)
return;
QDesignerObjectInspector *oi = 0;
if (QDesignerFormWindowInterface *fw = formWindow())
oi = qobject_cast<QDesignerObjectInspector *>(fw->core()->objectInspector());
if (!oi)
return;
oi->clearSelection();
oi->selectObject(menu);
}