PDA

View Full Version : Fullscreen QMainWindow, QGLWidget issue on OSX



yk555
28th June 2016, 16:28
I am using QT5.3 and using following code to add a QGLWidget to a layout of QMainWindow. (tried setCentralWidget as well)

In the QMainWindow("QtSystem_GameWindow" in the .ui file) init code:


QSizePolicy sizePolicy;
sizePolicy.setHorizontalPolicy(QSizePolicy::Expand ing);
sizePolicy.setVerticalPolicy(QSizePolicy::Expandin g);
m_pGLView->setSizePolicy(sizePolicy);
m_pGLView->resize(size());

QLayout* l = new QHBoxLayout(this);
l->setContentsMargins(0,0,0,0);
l->setSizeConstraint(QLayout::SizeConstraint::SetNoCo nstraint);
setLayout(l);
l->addWidget(m_pGLView);


When I am using the native fullscreen button on OSX to make the window(1600x900) go fullscreen, QGLWidget stays 1600x900 and there is black border around the QGLWidget.

Could anyone tell me what should I do to make the QGLWidget to fill the whole screen space and stays at the old size (for example 1600x900)?

Thanks in advance.

Here is the .ui file for the QMainWindow.


<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>QtSystem_GameWindow</class>
<widget class="QMainWindow" name="QtSystem_GameWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
</rect>
</property>
<property name="mouseTracking">
<bool>true</bool>
</property>
<property name="windowTitle">
<string>xxxxxx</string>
</property>
<property name="windowIcon">
<iconset resource="xxxxxx.qrc">
<normaloff>:/QtSystem_MainWindow/xxxxxx.ico</normaloff>:/QtSystem_MainWindow/xxxxxx.ico</iconset>
</property>
<widget class="QWidget" name="centralWidget"/>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>21</height>
</rect>
</property>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources>
<include location="xxxxxx.qrc"/>
</resources>
<connections/>
</ui>

anda_skoa
28th June 2016, 16:42
What is "this" in your code?
The widget taht you add as the central widget?

Cheers,
_

yk555
28th June 2016, 16:54
Sorry, forgot to mention "this" is the QMainWindow "QtSystem_GameWindow" in the .ui file.

anda_skoa
28th June 2016, 17:48
But a main window already has a layout.

Which of the main window elements do you currently need?
toolbars? statusbar?

Cheers,
_

yk555
29th June 2016, 09:06
But a main window already has a layout.

Which of the main window elements do you currently need?
toolbars? statusbar?

Cheers,
_
None, just a QGLWidget added to the main window.

anda_skoa
29th June 2016, 10:09
Then the question becomes: why use a QMainWindow at all?
Why not just have the GL widget as the window itself?

Cheers,
_

yk555
29th June 2016, 12:01
Then the question becomes: why use a QMainWindow at all?
Why not just have the GL widget as the window itself?

Cheers,
_

It's based on the Qt Widgets Application template in the Qt Creator.

anda_skoa
29th June 2016, 14:58
Ok, so if I understand you correctly, there is no reason to use the QMainWindow.

In which case just remove it and use your widget as the window.

Cheers,
_

yk555
30th June 2016, 10:30
Ok, so if I understand you correctly, there is no reason to use the QMainWindow.

In which case just remove it and use your widget as the window.

Cheers,
_

Thanks, just wonder if there is a way to make QGLWidget have a different framebuffer size from its actual size?

anda_skoa
30th June 2016, 11:39
No idea sorry.

Btw, I think the more current OpenGL widget is QOpenGLWidget, QGLWidget is deprecated

Cheers,
_

yk555
1st July 2016, 09:45
Thanks.

My final solution is to scale the offscreen buffer to fill the widget myself.