当前位置: 首页>>代码示例>>C++>>正文


C++ QDeclarativeItem::mapToScene方法代码示例

本文整理汇总了C++中QDeclarativeItem::mapToScene方法的典型用法代码示例。如果您正苦于以下问题:C++ QDeclarativeItem::mapToScene方法的具体用法?C++ QDeclarativeItem::mapToScene怎么用?C++ QDeclarativeItem::mapToScene使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QDeclarativeItem的用法示例。


在下文中一共展示了QDeclarativeItem::mapToScene方法的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());
        }
    }
开发者ID:ManoharUpputuri,项目名称:qt-labs-qtest-qml,代码行数:67,代码来源:quicktestevent.cpp


注:本文中的QDeclarativeItem::mapToScene方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。