在Retina显示屏中带有QOpenGLWIdget的Qt MainWindow显示错误的大小 [英] Qt MainWindow with QOpenGLWIdget in Retina display displays wrong size
问题描述
我有一个MainWindow
的Qt应用程序.
I have a Qt application with a MainWindow
.
我在其中嵌入了QOpenGLWidget
.一切正常,直到我开始使用Apple Retina显示器并以High DPI模式运行我的应用程序:我的QOpenGLWidget
只是它原本应该具有的大小的1/4(即,它仅填充了屏幕的左下角部分)应该填充的区域).此小部件正在显示原始OpenGL数据(实际上是一个OpenSceneGraph上下文)
I embed a QOpenGLWidget
in it. Everything works fine until I start using an Apple Retina Display and run my app in High DPI mode: my QOpenGLWidget
is just 1/4 of the size it was supposed to have (i.e., it only fills the bottom-left part of the area it is supposed to fill). This widget is displaying raw OpenGL data (actually, an OpenSceneGraph context)
该怎么办?
推荐答案
发现,对于OpenGL相关的小部件和事件,目前最好的选择是使用QPaintDevice::devicePixelRatio()
(
Found out that the best option for now, for OpenGL related widgets and events, is to use the QPaintDevice::devicePixelRatio()
(http://doc.qt.io/qt-5/qpaintdevice.html#devicePixelRatio)
这意味着将所有使用像素坐标的内容相乘,即鼠标事件,调整大小事件等等.示例:
This implies multiplying everything that uses pixel coordinates, i.e., mouse events, resizing events, and so on. Example:
void MyGLWidget::resizeGL(int width, int height) {
width *= Application::desktop()->devicePixelRatio();
height *= Application::desktop()->devicePixelRatio();
...
// Continue with previous code
}
在Retina/HighDPI显示器中以低分辨率模式运行时,或在常规显示器中运行时,该比例为1,因此对我来说似乎是可移植的.
When running in low resolution mode in a Retina/HighDPI display, or when running in a regular display, this ratio is 1, so this seems portable to me.
这篇关于在Retina显示屏中带有QOpenGLWIdget的Qt MainWindow显示错误的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!