Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to Fullscreen the child widget
Forum Updated to NodeBB v4.3 + New Features

How to Fullscreen the child widget

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 15.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    redstoneleo
    wrote on last edited by
    #1

    How to Fullscreen the child widget
    Un-subscribe from this thread

    How to Fullscreen the child widget

    The UI is as following
    http://img.my.csdn.net/uploads/201212/06/1354779576_2592.jpg

    What I want to do is that
    When doubleclick the black widget ,it should become in full screen mode ,then if I doubleclick again ,it should return back .
    So how to ?

    showFullScreen()only affects windows

    but when I setWindowFlags(Qt.Window) of that black widget ,the UI becomes like this

    http://img.my.csdn.net/uploads/201212/06/1354779928_2090.jpg

    so how can I implement this functionality ?

    BTW ,Phonon.VideoWidget Inherits QWidget and it has setFullScreen() method ,who know how it is implemented ?
    it would be better to give me some code example !

    1 Reply Last reply
    0
    • R Offline
      R Offline
      redstoneleo
      wrote on last edited by
      #2

      the black widget is QWidget

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sam
        wrote on last edited by
        #3

        The black widget lies inside the MainWindow of your application , so as per my understanding when you doubleClick on the black widget you want to maximize the application and if maximized then on double click you want to resize it back.

        One option is to subclass QWidget( for your black Widget) and reimplement mouseDoubleClick() function.

        Here is a test code :-

        MyWidget.h

        @class MyWidget : public QWidget
        {
        Q_OBJECT
        public:
        explicit MyWidget(QWidget *parent = 0);

        protected:
        void mouseDoubleClickEvent(QMouseEvent *event);

        signals:
        void doubleClicked();
        public slots:
        void onDoubleClicked();

        };@

        MyWidget.cpp

        @MyWidget::MyWidget(QWidget *parent) :
        QWidget(parent)
        {
        connect(this,SIGNAL(doubleClicked()),SLOT(onDoubleClicked()));
        }

        void MyWidget::mouseDoubleClickEvent(QMouseEvent *event)
        {
        emit doubleClicked();
        }

        void MyWidget::onDoubleClicked()
        {
        if (parentWidget()->isMaximized())
        {
        // you can implement to move the mainwindow to the center of screen.
        qDebug() << parentWidget(); //to see if parentWidget is mainwindow
        this->parentWidget()->resize(300,300);

        } else
        {
            this->parentWidget()->showMaximized();
        }
        

        }@

        Other option is that in your mainwindow you can override eventFilter() function and use installEventFilter() for your widget.

        code:-

        MainWindow.h

        @
        class MainWindow : public QMainWindow
        {
        Q_OBJECT

        public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();

        public slots:
        void onDoubleClicked();

        signals:
        void doubleClicked();

        protected:
        void mousePressEvent(QMouseEvent *event);
        bool eventFilter(QObject *target, QEvent *event);

        private:
        Ui::MainWindow *ui;
        QWidget *widget;

        };@

        MainWindow.cpp

        @MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
        {
        ui->setupUi(this);

        widget = new QWidget(this);
        widget->installEventFilter(this);
        widget->setAutoFillBackground(true);
        widget->setPalette(QPalette(Qt::red));
        
        setCentralWidget(widget);
        
        connect(this,SIGNAL(doubleClicked()),SLOT(onDoubleClicked()));
        

        }

        MainWindow::~MainWindow()
        {
        delete ui;
        }

        void MainWindow::onDoubleClicked()
        {
        if (isMaximized())
        {
        resize(300,300);

        } else
        {
            showMaximized();
        }
        

        }

        bool MainWindow::eventFilter(QObject *target, QEvent *event)
        {
        if (target == widget)
        {
        if (event->type() == QEvent::MouseButtonDblClick)
        {
        QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
        if (mouseEvent->button() == Qt::LeftButton )
        {
        emit doubleClicked();
        return QMainWindow::eventFilter(target,event);
        }
        }
        }
        return QMainWindow::eventFilter(target,event);
        }@

        1 Reply Last reply
        0
        • R Offline
          R Offline
          redstoneleo
          wrote on last edited by
          #4

          [quote author="Sam" date="1358402050"]The black widget lies inside the MainWindow of your application , so as per my understanding when you doubleClick on the black widget you want to maximize the application and if maximized then on double click you want to resize it back.

          One option is to subclass QWidget( for your black Widget) and reimplement mouseDoubleClick() function.

          Here is a test code :-

          MyWidget.h

          @class MyWidget : public QWidget
          {
          Q_OBJECT
          public:
          explicit MyWidget(QWidget *parent = 0);

          protected:
          void mouseDoubleClickEvent(QMouseEvent *event);

          signals:
          void doubleClicked();
          public slots:
          void onDoubleClicked();

          };@

          MyWidget.cpp

          @MyWidget::MyWidget(QWidget *parent) :
          QWidget(parent)
          {
          connect(this,SIGNAL(doubleClicked()),SLOT(onDoubleClicked()));
          }

          void MyWidget::mouseDoubleClickEvent(QMouseEvent *event)
          {
          emit doubleClicked();
          }

          void MyWidget::onDoubleClicked()
          {
          if (parentWidget()->isMaximized())
          {
          // you can implement to move the mainwindow to the center of screen.
          qDebug() << parentWidget(); //to see if parentWidget is mainwindow
          this->parentWidget()->resize(300,300);

          } else
          {
              this->parentWidget()->showMaximized();
          }
          

          }@

          Other option is that in your mainwindow you can override eventFilter() function and use installEventFilter() for your widget.

          code:-

          MainWindow.h

          @
          class MainWindow : public QMainWindow
          {
          Q_OBJECT

          public:
          explicit MainWindow(QWidget *parent = 0);
          ~MainWindow();

          public slots:
          void onDoubleClicked();

          signals:
          void doubleClicked();

          protected:
          void mousePressEvent(QMouseEvent *event);
          bool eventFilter(QObject *target, QEvent *event);

          private:
          Ui::MainWindow *ui;
          QWidget *widget;

          };@

          MainWindow.cpp

          @MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
          {
          ui->setupUi(this);

          widget = new QWidget(this);
          widget->installEventFilter(this);
          widget->setAutoFillBackground(true);
          widget->setPalette(QPalette(Qt::red));
          
          setCentralWidget(widget);
          
          connect(this,SIGNAL(doubleClicked()),SLOT(onDoubleClicked()));
          

          }

          MainWindow::~MainWindow()
          {
          delete ui;
          }

          void MainWindow::onDoubleClicked()
          {
          if (isMaximized())
          {
          resize(300,300);

          } else
          {
              showMaximized();
          }
          

          }

          bool MainWindow::eventFilter(QObject *target, QEvent *event)
          {
          if (target == widget)
          {
          if (event->type() == QEvent::MouseButtonDblClick)
          {
          QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
          if (mouseEvent->button() == Qt::LeftButton )
          {
          emit doubleClicked();
          return QMainWindow::eventFilter(target,event);
          }
          }
          }
          return QMainWindow::eventFilter(target,event);
          }@[/quote]

          NOTE : When doubleclick the black widget ,it should become in full screen mode ,i.e. the full screen of my computer should become black (that is just like a player play video in full screen mode )then if I doubleclick again ,it should return back .

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sam
            wrote on last edited by
            #5

            bq. NOTE : When doubleclick the black widget ,it should become in full screen mode ,i.e. the full screen of my computer should become black (that is just like a player play video in full screen mode )then if I doubleclick again ,it should return back .

            Thats more easy just set the following for your widget

            @setWindowFlags(this->windowFlags() | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint);
            setWindowState(this->windowState() | Qt::WindowFullScreen);@

            1 Reply Last reply
            0
            • R Offline
              R Offline
              redstoneleo
              wrote on last edited by
              #6

              [quote author="Sam" date="1358407182"]bq. NOTE : When doubleclick the black widget ,it should become in full screen mode ,i.e. the full screen of my computer should become black (that is just like a player play video in full screen mode )then if I doubleclick again ,it should return back .

              Thats more easy just set the following for your widget

              @setWindowFlags(this->windowFlags() | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint);
              setWindowState(this->windowState() | Qt::WindowFullScreen);@[/quote]

              Qt::WindowFullScreen only affects windows,but here the black widget is not window .

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Sam
                wrote on last edited by
                #7

                bq. Qt::WindowFullScreen only affects windows,but here the black widget is not window

                Are you sure ? coz that works for me , test code :-

                @widget = new QWidget();
                widget->setAutoFillBackground(true);
                widget->setPalette(QPalette(Qt::red));

                widget->setWindowFlags(widget->windowFlags() | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint);
                widget->setWindowState(widget->windowState() | Qt::WindowFullScreen);

                widget->show();@

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Sam
                  wrote on last edited by
                  #8

                  Okay here is the complete implementation

                  MainWindow.h

                  @class MainWindow : public QMainWindow
                  {
                  Q_OBJECT

                  public:
                  explicit MainWindow(QWidget *parent = 0);
                  ~MainWindow();

                  public slots:
                  void onDoubleClicked();

                  signals:
                  void doubleClicked();

                  protected:
                  bool eventFilter(QObject *target, QEvent *event);

                  private:
                  Ui::MainWindow *ui;
                  QWidget *widget;
                  bool isMaximized;
                  };@

                  MainWindow.cpp
                  @MainWindow::MainWindow(QWidget *parent) :
                  QMainWindow(parent),
                  ui(new Ui::MainWindow)
                  {
                  ui->setupUi(this);

                  isMaximized = false;
                  widget = new QWidget(this);
                  widget->installEventFilter(this);
                  widget->setAutoFillBackground(true);
                  widget->setPalette(QPalette(Qt::red));
                  
                  setCentralWidget(widget);
                  connect(this,SIGNAL(doubleClicked()),SLOT(onDoubleClicked()));
                  

                  }

                  MainWindow::~MainWindow()
                  {
                  delete ui;
                  }

                  void MainWindow::onDoubleClicked()
                  {
                  if ((widget->windowState() == Qt::WindowFullScreen) && isMaximized)
                  {
                  qDebug("Parent");
                  widget->setParent(this);
                  setCentralWidget(widget);
                  isMaximized = false;

                  } else
                  {
                      qDebug("Maximize");
                      isMaximized = true;
                      widget->setParent(NULL);
                      widget->setWindowFlags(widget->windowFlags() | Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint | Qt::WindowMaximizeButtonHint | Qt::WindowCloseButtonHint);
                      widget->setWindowState(widget->windowState() | Qt::WindowFullScreen);
                      widget->show();
                  
                  }
                  

                  }

                  bool MainWindow::eventFilter(QObject *target, QEvent *event)
                  {
                  if (target == widget)
                  {
                  if (event->type() == QEvent::MouseButtonDblClick)
                  {
                  QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
                  if (mouseEvent->button() == Qt::LeftButton )
                  {
                  emit doubleClicked();
                  return QMainWindow::eventFilter(target,event);
                  }
                  }
                  }
                  return QMainWindow::eventFilter(target,event);
                  }@

                  This works as required.

                  1 Reply Last reply
                  0
                  • W Offline
                    W Offline
                    wartburgritter
                    wrote on last edited by
                    #9

                    [quote author="redstoneleo" date="1358384982"]...
                    http://img.my.csdn.net/uploads/201212/06/1354779576_2592.jpg
                    ...
                    http://img.my.csdn.net/uploads/201212/06/1354779928_2090.jpg
                    ...
                    [/quote]

                    Hi I'm new but interested in this thread. The access to the jpgs is "403 Forbidden" ??!!

                    bernd

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Sam
                      wrote on last edited by
                      #10

                      @wartburgritt

                      Welcome to devnet,

                      Are you looking for a solution to the problem specified in the first post ?

                      For the above images you can have a look at "image 1":http://www.google.ae/imgres?hl=en&biw=1366&bih=667&tbm=isch&tbnid=2ldmN07Ro1xQ7M:&imgrefurl=http://qt-project.org/forums/viewthread/22520&docid=pf0wQKoyylj01M&imgurl=http://img.my.csdn.net/uploads/201212/06/1354779576_2592.jpg&w=812&h=628&ei=8rFIUaH-FoqQrgft1oDIDg&zoom=1&sa=X&ved=0CE0QhBwwAA&ved=1t:3588,r:0,s:0,i:77&iact=rc&dur=1845&page=1&tbnh=180&tbnw=233&start=0&ndsp=5&tx=187&ty=64 and "image 2":http://www.google.ae/imgres?hl=en&biw=1366&bih=667&tbm=isch&tbnid=eXbNTboHkH2fQM:&imgrefurl=http://qt-project.org/forums/viewthread/22520&docid=pf0wQKoyylj01M&imgurl=http://img.my.csdn.net/uploads/201212/06/1354779928_2090.jpg&w=812&h=628&ei=KLJIUeycE8PrrQfI8YGYBA&zoom=1&sa=X&ved=0CEoQhBwwAA&ved=1t:3588,r:0,s:0,i:74&iact=rc&dur=1107&page=1&tbnh=180&tbnw=233&start=0&ndsp=5&tx=101&ty=74

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved