Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Solution for mapToGlobal() in QGraphicsWidgetProxy
Qt 6.11 is out! See what's new in the release blog

Solution for mapToGlobal() in QGraphicsWidgetProxy

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 814 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    toteme
    wrote on last edited by
    #1

    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);
    }@

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved