精华内容
下载资源
问答
  • Qt全局坐标和相对坐标

    千次阅读 2018-03-16 14:53:45
    Qt全局坐标和相对坐标QMouseEvent中两类坐标系统,一类是窗口坐标,一类是显示器坐标。1、QPoint QMouseEvent::pos() 这个只是返回相对这个widget(重载了QMouseEvent的widget)的位置。 const Returns the position...
    Qt全局坐标和相对坐标

    QMouseEvent中两类坐标系统,一类是窗口坐标,一类是显示器坐标。

    1、QPoint QMouseEvent::pos() 

          这个只是返回相对这个widget(重载了QMouseEvent的widget)的位置。

           const Returns the position of the mouse cursor, relative to the widget that received the event. If you move the widget as a result of the mouse event, use the global position returned by globalPos() to avoid a shaking motion. 

    2、QPoint QMouseEvent::globalPos() 

         窗口坐标,这个是返回鼠标的全局坐标

         const Returns the global position of the mouse cursor at the time of the event. This is important on asynchronous window systems like X11. Whenever you move your widgets around in response to mouse events, globalPos() may differ a lot from the current pointer position QCursor::pos(), and from QWidget::mapToGlobal(pos()).

    3、QPoint QCursor::pos() [static] 

          返回相对显示器的全局坐标

          Returns the position of the cursor (hot spot) of the primary screen in global screen coordinates. You can call QWidget::mapFromGlobal() to translate it to widget coordinates. Note: The position is queried from the windowing system. If mouse events are generated via other means (e.g., via QWindowSystemInterface in a unit test), those fake mouse moves will not be reflected in the returned value. Note: On platforms where there is no windowing system or cursors are not available, the returned position is based on the mouse move events generated via QWindowSystemInterface.

    4.1  QPoint QWidget::mapToGlobal(const QPoint & pos)  const 

           将窗口坐标转换成显示器坐标

           Translates the widget coordinate pos to global screen coordinates. For example, mapToGlobal(QPoint(0,0)) would give the global coordinates of the top-left pixel of the widget. See also mapFromGlobal(), mapTo(), and mapToParent().

    4.2   QPoint QWidget::mapFromGlobal(const QPoint & pos) const 

           将显示器坐标转换成窗口坐标

           Translates the global screen coordinate pos to widget coordinates.

    5.1 QPoint QWidget::mapToParent(const QPoint & pos) const

           将窗口坐标获得的pos转换成父类widget的坐标

    Translates the widget coordinate pos to a coordinate in the parent widget.

    5.2 QPoint QWidget::mapFromParent(const QPoint & pos) const 

           将父类窗口坐标转换成当前窗口坐标

    Translates the parent widget coordinate pos to widget coordinates. Same as mapFromGlobal() if the widget has no parent.

    6.3 QPoint QWidget::mapTo(const QWidget * parent, const QPoint & pos) const 

           将当前窗口坐标转换成指定parent坐标。

    Translates the widget coordinate pos to the coordinate system of parent. The parent must not be 0 and must be a parent of the calling widget. See also mapFrom(), mapToParent(), mapToGlobal(), and underMouse().

    7、QWidget::pos() : QPoint

    这个属性获得的是当前目前控件在父窗口中的位置,

    This property holds the position of the widget within its parent widget.

    If the widget is a window, the position is that of the widget on the desktop, including its frame.

    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.

    By default, this property contains a position that refers to the origin.

    Warning: Calling move() or setGeometry() inside moveEvent() can lead to infinite recursion.

    See the Window Geometry documentation for an overview of geometry issues with windows.

    8、const QPointF & QMouseEvent::screenPos() const

    Returns the position of the mouse cursor as a QPointF, relative to the screen that received the event.

    和QPoint QMouseEvent::globalPos() 值相同,但是类型更高精度的QPointF

    This function was introduced in Qt 5.0.

    总结一:经过试验,QMouseEvent::globalPos()  和 QCursor::pos()效果一样,但是Qt帮助文档说不一样,可是我获得值确实相同的。

    QCursor::pos() == QMouseEvent::globalPos() 都是全局坐标;

    总结二:将button:posBtn直接转换成全局坐标。

    QMouseEvent::globalPos() ==  ui.posBtn->mapToGlobal(ui.posBtn->pos());

    总结三:将全局坐标(鼠标当前坐标,QCursor::pos())直接转换成当前

    当前窗口相对坐标 ==  ui.posBtn->mapFromGlobal(QCursor::pos());

    
    

    Qt中scene->setSceneRect

    在调用这个函数时并不是setSceneRect(0,0,width,height)这样,而是setSceneRect(-width/2,-height/2,width,height);即在QGraphicsView的坐标系统中Scene的原点并是不是顶点,而是中心点,与窗口的坐标系统不一致。

    在窗口显示图片http://blog.csdn.net/u010111033/article/details/53785223

    使用QLabel的setPixmap()就可以将图片显示出来,做视屏解码后显示也可以如此。但是为何我今天还要费力使用基函数drawPixmap()来做绘图

    展开全文
  • QT中获取控件相对全局坐标

    千次阅读 2020-09-28 09:16:57
    // 获取控件相对全局坐标 int btnPosX = snder->mapToGlobal(QPoint(0, 0)).x(); int btnPosY = snder->mapToGlobal(QPoint(0, 0)).y() 以下方式仅能获取相对于窗口的坐标: QPushButton *snder = ...

    例如获取窗口中按钮相对于屏幕的坐标:
    QPushButton *snder = (QPushButton *)sender();
    // 获取控件相对全局的坐标
    int btnPosX = snder->mapToGlobal(QPoint(0, 0)).x();
    int btnPosY = snder->mapToGlobal(QPoint(0, 0)).y()

    以下方式仅能获取相对于窗口的坐标:
    QPushButton *snder = (QPushButton *)sender();
    int btnPosX = snder->pos().x();
    int btnPosY = snder->pos().y()

    展开全文
  • QPoint QMouseEvent::globalPos() 窗口坐标,这个是返回鼠标的全局坐标 const Returns the global position of the mouse cursor at the time of theevent. This is important on asynchronous window systems like...

    1.     QPoint QMouseEvent::pos()

         这个只是返回相对这个widget(重载了QMouseEvent的widget)的位置。

          const Returns the position of the mouse cursor, relative to the widgetthat received the event. If you move the widget as a result of the mouse event,use the global position returned by globalPos() to avoid a shaking motion.

    2.     QPoint QMouseEvent::globalPos()

         窗口坐标,这个是返回鼠标的全局坐标

        const Returns the global position of the mouse cursor at the time of theevent. This is important on asynchronous window systems like X11. Whenever youmove your widgets around in response to mouse events, globalPos() may differ alot from the current pointer position QCursor::pos(), and fromQWidget::mapToGlobal(pos()).

    3.     QPoint QCursor::pos() [static]

         返回相对显示器的全局坐标

         Returns the position of the cursor (hot spot) of the primary screen inglobal screen coordinates. You can call QWidget::mapFromGlobal() to translateit to widget coordinates. Note: The position is queried from the windowingsystem. If mouse events are generated via other means (e.g., viaQWindowSystemInterface in a unit test), those fake mouse moves will not bereflected in the returned value. Note: On platforms where there is no windowingsystem or cursors are not available, the returned position is based on the mousemove events generated via QWindowSystemInterface.

    4.     QPoint QWidget::mapToGlobal(const QPoint & pos)  const

          将窗口坐标转换成显示器坐标

          Translates the widget coordinate pos to global screen coordinates. Forexample, mapToGlobal(QPoint(0,0)) would give the global coordinates of thetop-left pixel of the widget. See also mapFromGlobal(), mapTo(), andmapToParent().

    5.     QPoint QWidget::mapFromGlobal(const QPoint & pos) const

          将显示器坐标转换成窗口坐标

          Translates the global screen coordinate pos to widget coordinates.

    6.     QPoint QWidget::mapToParent(const QPoint & pos) const

          将窗口坐标获得的pos转换成父类widget的坐标

    Translates the widget coordinate pos to acoordinate in the parent widget.

    7.     QPoint QWidget::mapFromParent(const QPoint & pos) const

           将父类窗口坐标转换成当前窗口坐标

    Translates the parent widget coordinate posto widget coordinates. Same as mapFromGlobal() if the widget has no parent.

    8.     QPoint QWidget::mapTo(const QWidget * parent, const QPoint &pos) const

    将当前窗口坐标转换成指定parent坐标。

    Translates the widget coordinate pos to thecoordinate system of parent. The parent must not be 0 and must be a parent ofthe calling widget. See also mapFrom(), mapToParent(), mapToGlobal(), andunderMouse().

    9.     QWidget::pos() : QPoint

    这个属性获得的是当前目前控件在父窗口中的位置,

    This property holds the position of thewidget within its parent widget.

    If the widget is a window, the position isthat of the widget on the desktop, including its frame.

    When changing the position, the widget, ifvisible, receives a move event (moveEvent()) immediately. If the widget is notcurrently visible, it is guaranteed to receive an event before it is shown.

    By default, this property contains aposition that refers to the origin.

    Warning: Calling move() or setGeometry()inside moveEvent() can lead to infinite recursion.

    See the Window Geometry documentation foran overview of geometry issues with windows.

    10.    const QPointF &QMouseEvent::screenPos() const

    Returns the position of the mouse cursor asa QPointF, relative to the screen that received the event.

    和QPoint QMouseEvent::globalPos() 值相同,但是类型更高精度的QPointF

    This function was introduced in Qt 5.0.

    11.   QCursor::pos() == QMouseEvent::globalPos() 都是全局坐标

    12.   将鼠标的坐标转换成全局坐标。

    QMouseEvent::globalPos() == ui.posBtn->mapToGlobal(ui.posBtn->pos());

    13.   将全局坐标(鼠标当前坐标,QCursor::pos())直接转换成当前窗口相对坐标

    ui.posBtn->mapFromGlobal(QCursor::pos());

     

    展开全文
  • 窗口坐标,这个是返回鼠标的全局坐标 const Returns the global position of the mouse cursor at the time of theevent. This is important on asynchronous window systems like X11. Whenever youmove your ...

    原文链接:https://blog.csdn.net/fanyun_01/article/details/78369874

    1.QPoint QMouseEvent::pos()
    

    这个只是返回相对这个widget(重载了QMouseEvent的widget)的位置。
    const Returns the position of the mouse cursor, relative to the widgetthat received the event. If you move the widget as a result of the mouse event,use the global position returned by globalPos() to avoid a shaking motion.

    2.QPoint QMouseEvent::globalPos()
    

    窗口坐标,这个是返回鼠标的全局坐标
    const Returns the global position of the mouse cursor at the time of theevent. This is important on asynchronous window systems like X11. Whenever youmove your widgets around in response to mouse events, globalPos() may differ alot from the current pointer position QCursor::pos(), and fromQWidget::mapToGlobal(pos()).

    3.QPoint QCursor::pos() [static]
    

    返回相对显示器的全局坐标
    Returns the position of the cursor (hot spot) of the primary screen inglobal screen coordinates. You can call QWidget::mapFromGlobal() to translateit to widget coordinates. Note: The position is queried from the windowingsystem. If mouse events are generated via other means (e.g., viaQWindowSystemInterface in a unit test), those fake mouse moves will not bereflected in the returned value. Note: On platforms where there is no windowingsystem or cursors are not available, the returned position is based on the mousemove events generated via QWindowSystemInterface.

    4.QPoint QWidget::mapToGlobal(const QPoint & pos)  const
    

    将窗口坐标转换成显示器坐标
    Translates the widget coordinate pos to global screen coordinates. Forexample, mapToGlobal(QPoint(0,0)) would give the global coordinates of thetop-left pixel of the widget. See also mapFromGlobal(), mapTo(), andmapToParent().

    5.QPoint QWidget::mapFromGlobal(const QPoint & pos) const
    

    将显示器坐标转换成窗口坐标
    Translates the global screen coordinate pos to widget coordinates.

    6.QPoint QWidget::mapToParent(const QPoint & pos) const
    

    将窗口坐标获得的pos转换成父类widget的坐标

    Translates the widget coordinate pos to acoordinate in the parent widget.

    7.QPoint QWidget::mapFromParent(const QPoint & pos) const
    

    将父类窗口坐标转换成当前窗口坐标
    Translates the parent widget coordinate posto widget coordinates. Same as mapFromGlobal() if the widget has no parent.

    8.QPoint QWidget::mapTo(const QWidget * parent, const QPoint &pos) const
    

    将当前窗口坐标转换成指定parent坐标。

    Translates the widget coordinate pos to thecoordinate system of parent. The parent must not be 0 and must be a parent ofthe calling widget. See also mapFrom(), mapToParent(), mapToGlobal(), andunderMouse().

    9.QWidget::pos() : QPoint
    

    这个属性获得的是当前目前控件在父窗口中的位置,
    This property holds the position of thewidget within its parent widget.

    If the widget is a window, the position isthat of the widget on the desktop, including its frame.

    When changing the position, the widget, ifvisible, receives a move event (moveEvent()) immediately. If the widget is notcurrently visible, it is guaranteed to receive an event before it is shown.

    By default, this property contains aposition that refers to the origin.

    Warning: Calling move() or setGeometry()inside moveEvent() can lead to infinite recursion.

    See the Window Geometry documentation foran overview of geometry issues with windows.

    10.const QPointF &QMouseEvent::screenPos() const
    

    Returns the position of the mouse cursor asa QPointF, relative to the screen that received the event.
    和QPoint QMouseEvent::globalPos() 值相同,但是类型更高精度的QPointF
    This function was introduced in Qt 5.0.

    11.获取全局坐标

    QCursor::pos() == QMouseEvent::globalPos() 
    

    12. 将鼠标的坐标转换成全局坐标。

    QMouseEvent::globalPos() == ui.posBtn->mapToGlobal(ui.posBtn->pos());
    

    13.将全局坐标(鼠标当前坐标,QCursor::pos())直接转换成当前窗口相对坐标

    ui.posBtn->mapFromGlobal(QCursor::pos());
    
    展开全文
  • qt全局坐标和窗口坐标

    千次阅读 2015-07-03 17:46:33
    QMouseEvent中两类坐标系统,一类是窗口坐标,一类是显示器坐标。 1、QPoint QMouseEvent::pos()   这个只是返回相对这个widget(重载了QMouseEvent的widget)的位置。  const Returns the position of the mouse ...
  • 学习记录-Qt控件坐标

    千次阅读 2015-08-17 18:41:49
    使用Qt做了个界面,因为使用软键盘不能使用模态窗口,故自己使用frame做了一个自定义的弹窗,为了实现可拖动效果,重写鼠标事件,但遇到了控件坐标的问题, 怎么样获取鼠标落在控件事件进行处理。网上查看了几篇...
  • Qt获取控件位置坐标详解

    万次阅读 2017-10-27 22:15:13
     窗口坐标,这个是返回鼠标的全局坐标  const Returns the global position of the mouse cursor at the time of theevent. This is important on asynchronous window systems like X11. Whenever youmove ...
  • 拉伸某个控件的功能需要这些知识
  • 布局后,控件坐标默认为(0,0). 重写事件event获取 bool event(QEvent *e); bool getpos::event(QEvent *e) { if (QEvent::WindowActivate == e->type()) { //获取位置 } return QWidget::event(e); }
  • Qt获取控件位置,坐标总结

    千次阅读 2015-06-17 17:58:06
    Qt获取控件位置,坐标总结  总结的结果是: QMouseEvent中两类坐标系统,一类是窗口坐标,一类是显示器坐标。 总结一:经过试验,QMouseEvent::globalPos() 和 QCursor::pos()效果一样,...
  •  窗口坐标,这个是返回鼠标的全局坐标  const Returns the global position of the mouse cursor at the time of theevent. This is important on asynchronous window systems like X11. Whenever youmove ...
  • qt控件

    千次阅读 2019-05-06 09:42:37
    专业各种自定义控件编写+UI定制+输入法定制+视频监控+工业控制+仪器仪表+嵌入式linux+各种串口网络通信,童叟无欺,量大...Qt编写自定义控件大全 设计师designer完整源码(仅限Qt4):https://pan.baidu.com/s/1...
  • qt中关于坐标的说明

    千次阅读 2017-02-08 15:41:37
    qt中有两类坐标系统,一类是窗口坐标,一类是显示器坐标(全局坐标)。 QPoint QMouseEvent::pos() :返回相对这个widget的位置 QPoint QMouseEvent::globalPos() :窗口坐标,这个是返回鼠标的全局坐标 QPoint ...
  • qt控件的使用

    千次阅读 2014-08-23 09:50:14
    所有代码都是在qt3.3.8+fedora8下运行的。 1. 控件位置的确定 控件的位置一般来说是相对其父的其左上角的坐标: ...若要得到其针对全局界面的坐标值,则需要转换一下,用mapToGlobal(): QPoi
  • Qt控件的使用

    2011-11-05 18:49:33
    所有代码都是在qt3.3.8+fedora8下运行的。 1. 控件位置的确定 控件的位置一般来说是相对其父的其左上角的坐标: ...若要得到其针对全局界面的坐标值,则需要转换一下,用mapToGlobal(): QPoint
  • 思路:由于两个控件之间不存在直接的层级关系,需要先映射到全局坐标后作处理 错误姿势: //此处为窗口类作用域 QPoint posA = widgetA->mapToGlobal(widgetA->pos()); QPoint posB = this->mapFromGlobal...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 926
精华内容 370
关键字:

qt控件的全局坐标