Basically, you will need to have a way for the nested QGLWidget or it's parent to call showFullScreen() with another instance of your QGLWidget. Then have a way to go back.
To do this with a key press or a mouse click you need to reimplement QKeyEvent and QMouseEvent for all widgets that will have the focus when you want the fullscreen show and the fullscreen hide as an available option.
So depending on how many windows you are popping up and showing separately from your QMainWindow part of your GUI, you may want to have other windows also support a key press that will do the hide/show your fullscreen QGLWidget.
Here is a code snippet of how I did it once, but only with mouse interactions:
void MyWidget::enterEvent(QEvent *)
{
if(this->isFullScreen())
{
textItem->setText("Click again to return");
}
else
textItem->setText("Click for full screen");
// if(!clearTextTimer->isActive())
// clearTextTimer->start();
clearTextTimer->start();
this->update();
}
void MyWidget::mouseReleaseEvent(QMouseEvent *event)
{
static MyWidget * w = 0;
if(pixItem->contains(mapToScene(event->pos()))
&& event->button() != Qt::NoButton
&& w == 0)
{
w = new MyWidget();
w->showFullScreen();
}
else
{
if(this->isMaximized())
this->close();
else
w->close();
delete w;
w = 0;
}
}
You will also want to look at grabKeyboard() and releaseKeyboard().
setParent()
) to full screen and change parent again if it will be restored. – bkausbk