Solution for mapToGlobal() in QGraphicsWidgetProxy



  • It is useful when you have a scene with only one view:

    @QPoint mapPosToGlobal(const QPoint &pos, QWidget *widget)
    {
    QWidget *root = widget;
    while(root->parentWidget())
    root = root->parentWidget();

    QPoint root_pos = widget->mapTo(root, pos);

    QGraphicsProxyWidget *proxy = root->graphicsProxyWidget();
    if(proxy)
    {
    QGraphicsScene *scene = proxy->scene();

    if(scene && scene->views().count() == 1)
    {
    QPointF scene_pos = proxy->mapToScene(root_pos);

    QGraphicsView *view = scene->views().first();
    QPoint viewport_pos = view->mapFromScene(scene_pos);

    return view->viewport()->mapToGlobal(viewport_pos);
    }
    else
    return QPoint();
    }
    else
    return widget->mapToGlobal(pos);
    }@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.