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. QGraphicsItem set item pos using Cursor

QGraphicsItem set item pos using Cursor

Scheduled Pinned Locked Moved Solved General and Desktop
qgraphicssceneqgraphicsviewqcursor
2 Posts 1 Posters 513 Views
  • 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.
  • D Offline
    D Offline
    Dariusz
    wrote on 10 Dec 2021, 18:03 last edited by Dariusz 12 Oct 2021, 18:04
    #1

    Hey

    This is odd one.. I know... But what is the proper way to move item to cursor position. Say > item->setPos(QCursor::pos()) I tried all of the mapFromParent/Global/scene etc. I cant figure out which way I need to map it.
    Say mouseReleaseEvent>

            qDebug() << event;
            qDebug() << "E" << event->pos();
            qDebug() << "M" << QCursor::pos();
            qDebug() << "1" << mapFromGlobal(QCursor::pos());
            qDebug() << "2" << mapFromParent(QCursor::pos());
            qDebug() << "3" << mapToGlobal(QCursor::pos());
            qDebug() << "4" << mapToParent(QCursor::pos());
            qDebug() << "5" << mapFromScene(QCursor::pos());
            qDebug() << "6" << mapToScene(QCursor::pos());
        }
    

    Any hints?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      Dariusz
      wrote on 10 Dec 2021, 19:00 last edited by Dariusz 12 Oct 2021, 19:01
      #2

      For any1 wondering, its more or less >
      item->setPos(mNodeViewPtr->mapToScene(mNodeViewPtr->mapFromGlobal(QCursor::pos())));
      you can most likely do mNodeViewPtr->viewport()->mapFromGlobal() for more precision I think but I didn't test it.

      1 Reply Last reply
      1

      2/2

      10 Dec 2021, 19:00

      • Login

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