I have managed to turn fullscreen on/off by calling showFullScreen() and showNormal() for a QGLWidget that is the top level window of my Qt App. However, I would like to have a gl window derived from QGLWidget as part of a more complex GUI, parented to another mainwindow with other widgets in it(including another glwidget), and 开发者_运维知识库have this "primary" gl window be able to go fullscreen and back with a keystroke. I have not been able to find documentation showing me how to do this, any help?
Thanks!!
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().
精彩评论