查找 QWidget 所在的屏幕 [英] Find screen a QWidget is located on

查看:28
本文介绍了查找 QWidget 所在的屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

带函数

QApplication::desktop()->screenCount();
QApplication::desktop()->screenGeometry();

我找到了我的系统上有多少屏幕以及它们位于哪个屏幕坐标上.现在我想找出 QWidget 位于哪个屏幕上.我怎样才能做到这一点?我是否必须根据屏幕坐标检查 QWidget 的坐标,还是有更优雅的方法直接返回屏幕编号?

I find how much screens exist on my system and on which screen coordinates they are located. Now I want to find out on which screen a QWidget is located at. How can I do that? Do I have to check the coordinates of the QWidget against the screen-coordinates or is there a more elegant way for this which returns the screen-number directly?

谢谢!

推荐答案

我认为你应该寻找的功能是这个

I think the function you should be looking for is this

int QDesktopWidget::screenNumber(const QPoint &point) const

这是一个重载函数.返回包含该点的屏幕的索引,或与该点距离最短的屏幕.

This is an overloaded function. Returns the index of the screen that contains the point, or the screen which is the shortest distance from the point.

由于我没有多个屏幕,你可以自己检查,QWidget::pos() 函数提供了 QPoint

since i don't have multiple screens, you can check for yourself, the QWidget::pos() function provides the QPoint

正如 scopchanov 在评论中所建议的,您也可以使用

As suggested by scopchanov in comments, you can also use

QDesktopWidget::screenNumber(const QWidget *widget = Q_NULLPTR)

这篇关于查找 QWidget 所在的屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆