在Qt中获取物理屏幕尺寸
我在 Qt 中工作,我需要帮助来获取屏幕(监视器)的物理尺寸,
在 Qt 中,可以从 QApplication
获取 QDesktopWidget
,我的意思是
QDesktopWidget *mydesk = QApplication::desktop();
: QDesktopwidget
有一些方法可以获取以像素为单位的分辨率,还有一些方法可以获取以毫米为单位的尺寸:
mydesk-> widthMM(); mydesk->heightMM();
但是,这与物理尺寸不对应,当我用尺子测量屏幕时,有一个大量 不同之处。
另外,我们还可以获取 DPI 测量值并计算屏幕的大小:
mydesk->physicalDpiX(); mydesk->physicalDpiY();
double Winches = (double)mydesk.width() / (double)mydesk.physicalDpiX();
double Hinches = (double)mydesk.Height() / (double)mydesk.physicalDpiY();
其中 mydesk.width()
和 mydesk.height()
给出以像素为单位的大小(分辨率)
但是测量结果也是错误的,并且非常接近 mydesk.widthMM()
和 mydesk.heightMM()
我也尝试过 mydesk.ologicalDpiX()
它也有类似的结果。
I'km working in Qt, i need help to get the physical size of the screen (monitor),
In Qt one can get a QDesktopWidget
from QApplication
, I mean:
QDesktopWidget *mydesk = QApplication::desktop();
The QDesktopwidget
has some methods to get the resolution in pixels and some to get the the size in milimethers:
mydesk-> widthMM(); mydesk->heightMM();
However, this does not correspond to the physical size, when I measure my screen with a ruler, there is a considerable difference.
Also one can get the DPI measurement and calculate the size of the screen:
mydesk->physicalDpiX(); mydesk->physicalDpiY();
double Winches = (double)mydesk.width() / (double)mydesk.physicalDpiX();
double Hinches = (double)mydesk.Height() / (double)mydesk.physicalDpiY();
where mydesk.width()
and mydesk.height()
give the size in pixels(resolution)
However the measurement is also wrong and very close to mydesk.widthMM()
and mydesk.heightMM()
Also I have triyed mydesk.logicalDpiX()
and it has similar results.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我的(快速而肮脏的)示例。它似乎对我有用,我希望它对你有用。我假设您可以自己处理 main.cpp 。我在 MacBook Air 11.6" 上执行了此操作,并用一毛钱的图片替换了 OS X 中包含的美国图标:
Here is my (quick and dirty) example. It seems to work for me and I hope it works for you. I'm assuming you can take care of main.cpp on your own. I did this on a MacBook Air 11.6" and substituted a picture of a dime for the USA icon included with OS X:
以下方法可以帮助我获得屏幕的准确物理尺寸(以毫米为单位)。
然而,在Qt文档中我发现了下面这句话:
所以它可能不适用于您的系统。
The following method worked for me to get accurate physical size of my screen in mm.
However, in Qt documentation I found the following sentence:
So it might not work for your system.