title: PyQt5 get pos of another widget?
body: <p>I am trying to map one widgets <code>pos()</code> (A) to another widget (B), so that B can do some work based on A's position. I have <code>WidgetA</code> that gets <code>WidgetB</code> pos, these widgets can have different parenting hierarchy:</p>
  
  <pre><code>Global
  +--- Window
       +--- WidgetA
       +--- WidgetB
  
  Global
  +--- Window
       +--- Sub
       |    +--- Sub
       |         +--- WidgetB
       |
       +--- WidgetA
  
  Global
  +--- Window
  |    +--- WidgetB
  |
  +--- WidgetA
  </code></pre>
  
  <p>etc.</p>
  
  <p>I have tried to translate <code>B</code>'s position to a relative position on <code>A</code>' via (Both widgets share same parent):</p>
  
  <pre><code>WidgetB.setGeometry(150, 150, 100, 100)
  
                                                                   # expected vs result
  WidgetA.mapFromGlobal(WidgetB.mapToGlobal(WidgetB.pos()))        # 150, 150    125, 200
  WidgetA.mapFrom(WidgetA.parent, WidgetB.pos())                   # 150, 150    -25, 50
  WidgetA.parent.mapFromGlobal(WidgetB.mapToGlobal(WidgetB.pos())) # 150, 150    300, 300
  </code></pre>
  
  <p>What is the correct way to do this mapping? I cannot seem to wrap it correctly.</p>
  
  <p>Code:</p>
  
  <pre><code>from PyQt5.QtWidgets import QWidget, QApplication
  from PyQt5 import QtCore
  
  import sys
  
  class Window(QWidget):
  
      def __init__(self, Parent=None):
          super().__init__()
  
          self.WidgetA = QWidget(self)
          self.WidgetA.setAttribute(QtCore.Qt.WA_StyledBackground, True)
          self.WidgetA.setObjectName("WidgetA")
  
          self.WidgetA.setGeometry(400, 400, 100, 100)
  
          self.WidgetB = QWidget(self)
          self.WidgetB.setAttribute(QtCore.Qt.WA_StyledBackground, True)
          self.WidgetB.setObjectName("WidgetB")
  
          self.WidgetB.setGeometry(0, 0, 100, 100)
  
          self.setGeometry(0, 0, 500, 500)
  
          self.setStyleSheet("""
          #WidgetA {
              background-color: red;
          }
          #WidgetB {
              background-color: blue;
          }
          """)
  
      def resizeEvent(self, event):
          print(self.WidgetB.pos())
          print(self.WidgetA.pos())
  
          print(self.WidgetA.mapFromGlobal(self.WidgetB.mapToGlobal(self.WidgetB.pos())))
          print(self.WidgetA.mapFrom(self, self.WidgetB.pos()))
          print(self.mapFromGlobal(self.WidgetB.mapToGlobal(self.WidgetB.pos())))
  
  
  
  
  if __name__ == "__main__":
  
      app = QApplication(sys.argv)
  
      screen = Window()
      screen.show()
  
      sys.exit(app.exec_())
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>PyQt5.QtCore.QPoint()
  PyQt5.QtCore.QPoint(400, 400)
  PyQt5.QtCore.QPoint(-400, -400)
  PyQt5.QtCore.QPoint(-400, -400)
  PyQt5.QtCore.QPoint()
  </code></pre>
  
  <p>I would expect to get <code>(0, 0)</code> since that is what <code>WidgetB</code> is set to.</p>