Qt Widget temporarily fullscreen

Consider a QWidget, usually a child in a layout.

Suppose I want to make it fullScreen for a while, and then return it to its old place.

QWidget::setFullScreen() requires the widget to be an independent window - any ideas how to solve it?

+5
source share
2 answers

The easiest way I can see is to repeat 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();
}
+3
source

I modified the previous example. The previous example never returns to the normal screen.

Just paste the code and it will work.

        #include <QApplication>
        #include <QPushButton>

        class MyButton : public QPushButton
        {
        public:
           MyButton(QWidget* parent) : QPushButton(parent) {
               m_pParent = parent;
               maxMode = false;
           }
           QWidget * m_pParent;
           bool maxMode;
           Qt::WindowFlags m_enOrigWindowFlags;
           QSize m_pSize;

           void mousePressEvent(QMouseEvent*) {
               if (maxMode== false)
               {
                   m_enOrigWindowFlags = this->windowFlags();
                   m_pSize = this->size();
                    this->setParent(0);
                    this->setWindowFlags( Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);
                    this->showMaximized();
                    maxMode = true;
               }
               else
               {
                   this->setParent(m_pParent);
                   this ->resize(m_pSize);
                   this->overrideWindowFlags(m_enOrigWindowFlags);
                   this->show();
                   maxMode =  false;
               }
           }
        };

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

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

           return a.exec();
        }
+1
source

All Articles