qt全屏实现与恢复

全屏关键代码如下:

QRect rect0;

rect0 = ui->offFullScreenWidget->geometry();//记录widget位置,恢复时使用

ui->offFullScreenWidget->setWindowFlags(Qt::Window);

ui->offFullScreenWidget->showFullScreen();

以esc按键恢复为例:

首先注册捕捉事件:ui->offFullScreenWidget->installEventFilter(this);

处理函数如下:

bool xxx::eventFilter(QObject *obj, QEvent *ev)
{

    if(ev->type() == QEvent::KeyPress){

            if(obj == ui->offFullScreenWidget){

                if(event->key() == Qt::Key_Escape){
                    ui->offFullScreenWidget->setWindowFlags(Qt::SubWindow);
                    ui->offFullScreenWidget->showNormal();
                    ui->offFullScreenWidget->setGeometry(rect0);

                }

            }

    }

}

完毕!

你可能感兴趣的:(qt)