如何在 Qt 中获取鼠标在屏幕上的位置?

Posted

技术标签:

【中文标题】如何在 Qt 中获取鼠标在屏幕上的位置?【英文标题】:How to get the mouse position on the screen in Qt? 【发布时间】:2013-10-22 16:27:53 【问题描述】:

我想获取鼠标在屏幕上的坐标。

如何在 Qt 中做到这一点?


在 Windows 上,使用 C# 我正在做类似答案to this question 中建议的事情。

【问题讨论】:

【参考方案1】:

如文档所述:-

QCursor::pos()

返回主屏幕光标(热点)的位置 全局屏幕坐标。

如果你有多个屏幕,你可以使用:-

QPoint QCursor::pos(const QScreen * screen) 

请注意,QScreen 用于 Qt 5

【讨论】:

【参考方案2】:

试试这个:

QCursor::pos()

应该可以完美运行

【讨论】:

以上是关于如何在 Qt 中获取鼠标在屏幕上的位置?的主要内容,如果未能解决你的问题,请参考以下文章