Qt中的坐标位置

最近看了些代码,被各种pos(), globalpos()之类的差异搞迷糊了,心想来整理一下区别,主要看help,个人理解,不一定对,若有大佬路过,不吝指点,幸甚。

在这里插入图片描述

用图片来说明一下可能更清楚,总得来说应该有3个坐标系:
1、全局的桌面坐标系,坐标轴原点为O1,
2、widget的父widget坐标系,主要用于定位当前widget在父widget中的位置,原点为当前widget的父widget的左上角位置,这里为O2
3、widget坐标系,用于定位widget内部位置,坐标轴原点为O3

  • [static] QPoint QCursor::pos()

Returns the position of the cursor (hot spot) of the primary screen in global screen coordinates. 返回鼠标在全局坐标位置,即相对于桌面坐标系统原点O1的坐标位置

  • pos : QPoint

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(),效果是一致的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值