本文整理汇总了C++中QMenu::actionAt方法的典型用法代码示例。如果您正苦于以下问题:C++ QMenu::actionAt方法的具体用法?C++ QMenu::actionAt怎么用?C++ QMenu::actionAt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMenu
的用法示例。
在下文中一共展示了QMenu::actionAt方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
QAction *QMenuProto::actionAt(const QPoint &pt) const
{
QMenu *item = qscriptvalue_cast<QMenu*>(thisObject());
if (item)
return item->actionAt(pt);
return 0;
}
示例2: eventFilter
bool MainWindow::eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::ContextMenu && object->objectName().contains(QLatin1String("bookmarks"), Qt::CaseInsensitive))
{
QContextMenuEvent *contextMenuEvent = static_cast<QContextMenuEvent*>(event);
QMenu *menu = qobject_cast<QMenu*>(object);
if (contextMenuEvent && menu)
{
QAction *action = menu->actionAt(contextMenuEvent->pos());
if (action && action->data().type() == QVariant::String)
{
m_currentBookmark = action->data().toString();
QMenu contextMenu(this);
contextMenu.addAction(Utils::getIcon(QLatin1String("document-open")), tr("Open"), this, SLOT(openBookmark()));
contextMenu.addAction(tr("Open in New Tab"), this, SLOT(openBookmark()))->setData(NewTabOpen);
contextMenu.addAction(tr("Open in New Background Tab"), this, SLOT(openBookmark()))->setData(NewTabBackgroundOpen);
contextMenu.addSeparator();
contextMenu.addAction(tr("Open in New Window"), this, SLOT(openBookmark()))->setData(NewWindowOpen);
contextMenu.addAction(tr("Open in New Background Window"), this, SLOT(openBookmark()))->setData(NewWindowBackgroundOpen);
contextMenu.exec(contextMenuEvent->globalPos());
return true;
}
}
}
if (event->type() == QEvent::KeyPress && isFullScreen())
{
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
if (keyEvent->key() == Qt::Key_Escape)
{
actionFullScreen();
}
}
return QMainWindow::eventFilter(object, event);
}
示例3: actionGeometry
void tst_QToolBar::actionGeometry()
{
QToolBar tb;
QAction action1(0);
QAction action2(0);
QAction action3(0);
QAction action4(0);
tb.addAction(&action1);
tb.addAction(&action2);
tb.addAction(&action3);
tb.addAction(&action4);
tb.show();
#ifdef Q_WS_X11
qt_x11_wait_for_window_manager(&tb);
#endif
QList<QToolBarExtension *> extensions = tb.findChildren<QToolBarExtension *>();
QRect rect01;
QRect rect02;
QRect rect03;
QRect rect04;
QMenu *popupMenu;
if (extensions.size() != 0)
{
QToolBarExtension *extension = extensions.at(0);
if (extension->isVisible()) {
QRect rect0 = extension->geometry();
QTest::mouseClick( extension, Qt::LeftButton, 0, rect0.center(), -1 );
QApplication::processEvents();
popupMenu = qobject_cast<QMenu *>(extension->menu());
rect01 = popupMenu->actionGeometry(&action1);
rect02 = popupMenu->actionGeometry(&action2);
rect03 = popupMenu->actionGeometry(&action3);
rect04 = popupMenu->actionGeometry(&action4);
}
}
QRect rect1 = tb.actionGeometry(&action1);
QRect rect2 = tb.actionGeometry(&action2);
QRect rect3 = tb.actionGeometry(&action3);
QRect rect4 = tb.actionGeometry(&action4);
QVERIFY(rect1.isValid());
QVERIFY(!rect1.isNull());
QVERIFY(!rect1.isEmpty());
QVERIFY(rect2.isValid());
QVERIFY(!rect2.isNull());
QVERIFY(!rect2.isEmpty());
QVERIFY(rect3.isValid());
QVERIFY(!rect3.isNull());
QVERIFY(!rect3.isEmpty());
QVERIFY(rect4.isValid());
QVERIFY(!rect4.isNull());
QVERIFY(!rect4.isEmpty());
if (rect01.isValid())
QCOMPARE(popupMenu->actionAt(rect01.center()), &action1);
else
QCOMPARE(tb.actionAt(rect1.center()), &action1);
if (rect02.isValid())
QCOMPARE(popupMenu->actionAt(rect02.center()), &action2);
else
QCOMPARE(tb.actionAt(rect2.center()), &action2);
if (rect03.isValid())
QCOMPARE(popupMenu->actionAt(rect03.center()), &action3);
else
QCOMPARE(tb.actionAt(rect3.center()), &action3);
if (rect04.isValid())
QCOMPARE(popupMenu->actionAt(rect04.center()), &action4);
else
QCOMPARE(tb.actionAt(rect4.center()), &action4);
}
示例4: eventFilter
//.........这里部分代码省略.........
///////////////////////////////////////////////////////
// take the sending object
QObject* o = obj;
QObject* parent = 0;
x_ = y_ = 0;
// for mouse events: take widget under the mouse cursor
if (me != 0)
{
widget_ = qApp->widgetAt(me->globalPos());
if (widget_ == 0) return false;
if (widget_->objectName() == "" &&
widget_->actions().size() == 0)
{
widget_ = dynamic_cast<QWidget*>(widget_->parent());
if (widget_ == 0 || widget_->objectName() == "") return false;
}
o = widget_;
QPoint global = me->globalPos();
// if we can not get local coordinates: abort
QPoint local = widget_->mapFromGlobal(global);
if (local.x() < 0 || local.y() < 0 ||
local.x() >= widget_->width() || local.y() >= widget_->height())
{
return false;
}
// for menus: take the position of the action under the cursor
QMenu* menu = dynamic_cast<QMenu*>(o);
if (menu)
{
QAction* action = menu->actionAt(local);
if (action != 0)
{
o = action;
parent = menu;
QRect rect = menu->actionGeometry(action);
local.rx() -= rect.x();
local.ry() -= rect.y();
if (rect.width() == 0 || rect.height() == 0) return false;
x_ = local.x();
y_ = local.y();
}
}
if (x_ == 0 && y_ == 0)
{
// take the position as percent of the widget's actual size
if (widget_->width() == 0 || widget_->height() == 0) return false;
x_ = local.x();
y_ = local.y();
}
}
String names;
while (o != 0)
{
String name = ascii(o->objectName());
if (name == "")
{
QWidget* widget = dynamic_cast<QWidget*>(o);
if (widget != 0)
{
示例5: translateEvent
// ----------------------------------------------------------------------------
bool qMRMLTreeViewEventTranslator::translateEvent(QObject *Object,
QEvent *Event,
int EventType,
bool &Error)
{
Q_UNUSED(Error);
qMRMLTreeView* treeView = NULL;
for(QObject* test = Object; treeView == NULL && test != NULL; test = test->parent())
{
treeView = qobject_cast<qMRMLTreeView*>(test);
}
// qMRMLTreeView* treeView = qobject_cast<qMRMLTreeView*>(Object);
if(!treeView)
{
return false;
}
// For the custom action when we have a right click
QMenu* menu = NULL;
for(QObject* test = Object; menu == NULL && test != NULL ; test = test->parent())
{
menu = qobject_cast<QMenu*>(test);
}
if (menu)
{
if(Event->type() == QEvent::KeyPress)
{
QKeyEvent* e = static_cast<QKeyEvent*>(Event);
if(e->key() == Qt::Key_Enter)
{
QAction* action = menu->activeAction();
if(action)
{
QString which = action->objectName();
if(which == QString::null)
{
which = action->text();
}
if (which != "Rename" && which != "Delete" )
{
emit recordEvent(menu, "activate", which);
}
}
}
}
if(Event->type() == QEvent::MouseButtonRelease)
{
QMouseEvent* e = static_cast<QMouseEvent*>(Event);
if(e->button() == Qt::LeftButton)
{
QAction* action = menu->actionAt(e->pos());
if (action && !action->menu())
{
QString which = action->objectName();
if(which == QString::null)
{
which = action->text();
}
if (which != "Rename" && which != "Delete" )
{
emit recordEvent(menu, "activate", which);
}
}
}
}
return true;
}
// We want to stop the action on the QDialog when we are renaming
// and let passed the action for the "set_current".
QInputDialog* dialog = NULL;
for(QObject* test = Object; dialog == NULL && test != NULL; test = test->parent())
{
dialog = qobject_cast<QInputDialog*>(test);
if(dialog)
{
// block actions on the QInputDialog
return true;
}
}
if(Event->type() == QEvent::Enter && Object == treeView)
{
if(this->CurrentObject != Object)
{
if(this->CurrentObject)
{
disconnect(this->CurrentObject, 0, this, 0);
}
this->CurrentObject = Object;
connect(treeView, SIGNAL(destroyed(QObject*)),
this, SLOT(onDestroyed(QObject*)));
connect(treeView, SIGNAL(currentNodeRenamed(QString)),
this, SLOT(onCurrentNodeRenamed(QString)));
// Can be better to do it on the model to recover the QModelIndex
connect(treeView, SIGNAL(currentNodeDeleted(const QModelIndex&)),
//.........这里部分代码省略.........