本文整理汇总了C++中QDeclarativeView::mapFromScene方法的典型用法代码示例。如果您正苦于以下问题:C++ QDeclarativeView::mapFromScene方法的具体用法?C++ QDeclarativeView::mapFromScene怎么用?C++ QDeclarativeView::mapFromScene使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDeclarativeView
的用法示例。
在下文中一共展示了QDeclarativeView::mapFromScene方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mouseEvent
static void mouseEvent(MouseAction action, QWidget *widget,
QObject *item, Qt::MouseButton button,
Qt::KeyboardModifiers stateKey, QPointF _pos, int delay=-1)
{
QTEST_ASSERT(widget);
QTEST_ASSERT(item);
if (delay == -1 || delay < QTest::defaultMouseDelay())
delay = QTest::defaultMouseDelay();
if (delay > 0)
QTest::qWait(delay);
if (action == MouseClick) {
mouseEvent(MousePress, widget, item, button, stateKey, _pos);
mouseEvent(MouseRelease, widget, item, button, stateKey, _pos);
return;
}
QPoint pos;
QDeclarativeView *view = qobject_cast<QDeclarativeView *>(widget);
QWidget *eventWidget = widget;
QDeclarativeItem *ditem = qobject_cast<QDeclarativeItem *>(item);
if (!ditem) {
qWarning("Mouse event target is not an Item");
return;
}
pos = view->mapFromScene(ditem->mapToScene(_pos));
eventWidget = view->viewport();
QTEST_ASSERT(button == Qt::NoButton || button & Qt::MouseButtonMask);
QTEST_ASSERT(stateKey == 0 || stateKey & Qt::KeyboardModifierMask);
stateKey &= static_cast<unsigned int>(Qt::KeyboardModifierMask);
QMouseEvent me(QEvent::User, QPoint(), Qt::LeftButton, button, stateKey);
switch (action)
{
case MousePress:
me = QMouseEvent(QEvent::MouseButtonPress, pos, widget->mapToGlobal(pos), button, button, stateKey);
break;
case MouseRelease:
me = QMouseEvent(QEvent::MouseButtonRelease, pos, widget->mapToGlobal(pos), button, 0, stateKey);
break;
case MouseDoubleClick:
me = QMouseEvent(QEvent::MouseButtonDblClick, pos, widget->mapToGlobal(pos), button, button, stateKey);
break;
case MouseMove:
if (button == Qt::NoButton) {
// If we send a mouse move event with no button pressed, it will be
// rejected (unless mouseTracking is set to true); simulate instead
QCursor::setPos(widget->mapToGlobal(pos));
qApp->processEvents();
} else {
me = QMouseEvent(QEvent::MouseMove, pos, widget->mapToGlobal(pos), button, button, stateKey);
}
break;
default:
QTEST_ASSERT(false);
}
QSpontaneKeyEvent::setSpontaneous(&me);
if (!qApp->notify(eventWidget, &me)) {
static const char *mouseActionNames[] =
{ "MousePress", "MouseRelease", "MouseClick", "MouseDoubleClick", "MouseMove" };
QString warning = QString::fromLatin1("Mouse event \"%1\" not accepted by receiving widget");
QTest::qWarn(warning.arg(QString::fromLatin1(mouseActionNames[static_cast<int>(action)])).toAscii().data());
}
}