最近看了些代码,被各种pos(), globalpos()之类的差异搞迷糊了,心想来整理一下区别,主要看help,个人理解,不一定对,若有大佬路过,不吝指点,幸甚。
用图片来说明一下可能更清楚,总得来说应该有3个坐标系:
1、全局的桌面坐标系,坐标轴原点为O1,
2、widget的父widget坐标系,主要用于定位当前widget在父widget中的位置,原点为当前widget的父widget的左上角位置,这里为O2
3、widget坐标系,用于定位widget内部位置,坐标轴原点为O3
Returns the position of the cursor (hot spot) of the primary screen in global screen coordinates. 返回鼠标在全局坐标位置,即相对于桌面坐标系统原点O1的坐标位置
This property holds the position of the widget within its parent widget
这个属性表示的是当前widget相对于其父widget的位置,(这边widget的parent为Mainwindow)即当前widget的左上角O3点,在以O2为坐标轴原点的坐标位置。widget没有移动,pos()也是不变的,跟鼠标点位置没关系。
If the widget is a window, the position is that of the widget on the desktop, including its frame.如果widget是个窗口,pos()表示widget在桌面的位置,包含边框
When changing the position, the widget, if visible, receives a move event (moveEvent()) immediately. If the widget is not currently visible, it is guaranteed to receive an event before it is shown.懒得翻,单纯觉着这段精辟。
注:pos().x() 有时候直接写成x(),效果是一致的