Qt Widget暂时全屏 [英] Qt Widget temporarily fullscreen

查看:322
本文介绍了Qt Widget暂时全屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑一个QWidget,通常是某些Layout中的子级.

Consider a QWidget, normally a child in some Layout.

假设我想让它全屏一段时间,然后让它回到原来的位置.

Supposed I want to make it fullScreen for a while, then have it return to it's old spot.

QWidget::setFullScreen()要求该小部件需要是一个独立的窗口-关于如何实现它的任何想法?

QWidget::setFullScreen() requires that the widget needs to be an independent window - any ideas how to work it out?

推荐答案

我看到的最简单的方法是将其重设为0.

The simplest way I can see is to reparent to 0. Something like this:

#include <QApplication>
#include <QPushButton>

class MyButton : public QPushButton
{
public:
   MyButton(QWidget* parent) : QPushButton(parent) {}

   void mousePressEvent(QMouseEvent*) {
      this->setParent(0);
      this->showMaximized();
      this->show();
   }
};

int main(int argc, char *argv[])
{
   QApplication a(argc, argv);

   QWidget mainWidget;
   MyButton button(&mainWidget);
   mainWidget.show();

   return a.exec();
}

这篇关于Qt Widget暂时全屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆