title: Create a full Screen Button in PYQT5
body: <p>Start of the application</p>
  
  <p><img src="https://i.stack.imgur.com/SZJBZ.png" alt=""></p>
  
  <p>Plot the Graph</p>
  
  <p><img src="https://i.stack.imgur.com/BzuhA.png" alt=""></p>
  
  <p>Full Screen</p>
  
  <p><img src="https://i.stack.imgur.com/aYNKc.png" alt=""></p>
  
  <p>I have an application with 4 Box on the main window, and I want to had a full screen button in a windows which plot some graph, like on the Pictures on the top.</p>
  
  <p>I first try a method to creating a fullScreen function in my code, linked to the button, but it is no work.</p>
  
  <p>Here is my try :</p>
  
  <pre><code>class mainApplication(QWidget):
  
      def __init__(self, parent=None):
          super(mainApplication, self).__init__(parent)
  
          self.layoutMap = {}
          self.buttonMap = {}
  
          # Figure Bottom Right
          self.figure = plt.figure(figsize=(15,5))
          self.figure.set_facecolor('0.915')
          self.canvas = FigureCanvas(self.figure) 
  
          # Main Figure
          self.setGeometry(600, 300, 1000, 600)
  
          self.topLeft()
          self.topRight()
          self.bottomLeft()
          self.bottomRight()
  
          mainLayout = QGridLayout()
          mainLayout.addWidget(self.topLeftBox, 1, 0)
          mainLayout.addWidget(self.topRightBox, 1, 1)
          mainLayout.addWidget(self.bottomLeftBox, 2, 0)
          mainLayout.addWidget(self.bottomRightBox, 2, 1)
          mainLayout.setRowStretch(1, 1)
          mainLayout.setRowStretch(2, 1)
          mainLayout.setColumnStretch(0, 1)
          mainLayout.setColumnStretch(1, 1)
          self.saveLayout(mainLayout, "main")
  
          self.setLayout(mainLayout)
  
          self.setWindowTitle("Title")
          QApplication.setStyle("Fusion")
          self.show()
  
      def bottomRight(self):
  
          self.bottomRightBox = QGroupBox("Bottom Right")
  
          # Create Select Button
          chooseButton = QPushButton("Select")
          chooseButton.setMaximumWidth(100)
          chooseButton.setMaximumHeight(20)
          self.saveButton(chooseButton)
          chooseButton.clicked.connect(self.selectFunction)
  
          # Create Full Screen Button
          fullScreenButton = QPushButton("Full")
          fullScreenButton.setMaximumWidth(100)
          fullScreenButton.setMaximumHeight(20)
          self.saveButton(fullScreenButton)
          fullScreenButton.clicked.connect(self.swichFullScreen)
  
          # Create Layout
          layout = QVBoxLayout()
          layout.addWidget(self.canvas)
          layout.addWidget(chooseButton)
          layout.addWidget(fullScreenButton)
          layout.addStretch(1)
  
          self.saveLayout(layout, "full")
  
  
          # Add Layout to GroupBox
          self.bottomRightBox.setLayout(layout)   
  
  
      def selectFunction(self):
  
          # Select Data
          filePath, _ = QtWidgets.QFileDialog.getOpenFileName(self, 'Open file', '/Data/')
          df = pd.read_csv(str(filePath))
          x = df.x.tolist()
          y = df.y.tolist()
  
          # Create Figure
          self.figure.clf()
          ax = self.figure.add_subplot(111)
          ax.plot(x, y)
          ax.set_facecolor('0.915')
          ax.set_title('Graphique')
  
          # Draw Graph
          self.canvas.draw()
  
      def saveLayout(self,obj, text):
           self.layoutMap[text] = obj
  
      def findLayout(self,text):
           return self.layoutMap[text]
  
      def saveButton(self,obj):
           self.buttonMap[obj.text()] = obj
  
      def findButton(self,text):
           return self.buttonMap[text]
  
  
      def swichFullScreen(self):
          self.setLayout(self.findLayout("full"))
          self.show()
  
  
  
  
  
  if __name__ == '__main__':
  
      app = QApplication(sys.argv)
      mainWindow = mainApplication()
      sys.exit(app.exec_())
  </code></pre>
  
  <p>Have you an idea? because for example, if in my initialization I don't do :</p>
  
  <pre><code>self.setLayout(mainLayout)
  </code></pre>
  
  <p>but :</p>
  
  <pre><code>swichFullScreen()
  </code></pre>
  
  <p>I have the result that I want, so why call this fonction after the creation of my main layout don't work?</p>
  
  <p>Moreover, I have try an other thing adapter from this : <a href="https://stackoverflow.com/questions/41290035/pyqt-change-gui-layout-after-button-is-clicked">PyQt: Change GUI Layout after button is clicked</a></p>
  
  <p>But it still not worked because when I clic on the button "full", it switch very well, but the normalWindow object has been delete so the button select stop to work.</p>
  
  <p>If you have a solution for my first idea, I prefer because it avoid the creation of other class, but if it is not possible and that you find a solution for the second solution to avoid the destruction of the object, I take it too.</p>
  
  <p>Here the code for my second solution :</p>
  
  <pre><code>class fullScreenApplication(QWidget):
      def __init__(self, parent=None):
          super(fullScreenApplication, self).__init__(parent)
          self.setGeometry(600, 300, 1000, 600)
  
  
  class MainWindow(QMainWindow):
      def __init__(self, parent=None):
          super(MainWindow, self).__init__(parent)
          self.setGeometry(600, 300, 1000, 600)
          self.normalWindows()
  
      def normalWindows(self):
          self.normalBox = mainApplication(self)
          self.setCentralWidget(self.normalBox)
          self.normalBox.findButton("Full").clicked.connect(self.fullScreenWindow)
          self.show()
  
      def fullScreenWindow(self):
          self.FullBox = fullScreenApplication(self)
          self.FullBox.setLayout(self.normalBox.findLayout("full"))
          self.normalBox.findButton("Full").clicked.connect(self.normalWindows)
          self.normalBox.findButton("Select").clicked.connect(self.normalBox.selectFunction)
          self.setCentralWidget(self.FullBox)
          self.show()
  
  
  
  
  
  if __name__ == '__main__':
  
      app = QApplication(sys.argv)
      mainWindow = MainWindow()
      sys.exit(app.exec_()) 
  </code></pre>
  
  <p>Thank you </p>