title: PYQT5 - How to Display a QtableWidget on the current page after pressing a button
body: <p>I'm trying to do an GUI with python, i'm in a difficult part for me.
  I'm working with json file too.</p>
  <p>Today, i have a normal Qtable visible with 9 ColumnHeader and i insert row with informations of my json, but i want to change that with a qtable created after my first test.</p>
  <p>(Important think: When i say dynamically Qtable, it's because : 1) I have no information in row at first (this is working), 2) my ColumnHeaderItem = have to be keys of my json file, no key available when i create my json)
  During actions, i stay in the same page &quot;display-table&quot;</p>
  <p>First, i want to join my page &quot;display-table&quot; when i press a button (is working). In this page i don't want to see my Qtable because she have no information yet, row and column.</p>
  <p>Second, i launch a test procedure, i write in my json data and keys, keys are available for my Qtable  ColumnHeaderItem and test informations for rows. (Keys looks like : LNA, Filter, Frequency Min....i have 9 keys).</p>
  <p>Actions :
  -Press button =&gt;</p>
  <pre><code> def json_creation(self):
          &quot;&quot;&quot;
          Json Création 
          &quot;&quot;&quot;
  
          parameters_projet = {
              &quot;user&quot;: self.user,
              &quot;project&quot;: self.project,
              &quot;site&quot;: self.site,
              &quot;Test&quot;: []
  
          }
          #Opening + writing
          with open('./data/' + self.user + '_' + self.project + '_' + self.site + '.json', 'w') as file:
              json_pjt = json.dumps(parameters_projet)
              file.write(json_pjt + &quot;\n&quot;)
              # Ajoute du bouton Link, visualisation de la pop up data
              self.b_link = QtWidgets.QPushButton(self.centralwidget)
              self.b_link.setText(&quot;Open data&quot;)
              # Désactivé car 0 test
              self.b_link.isEnabled()
              file.close()
  
  
          with open('./data/' +self.user + '_' + self.project + '_' + self.site + '.json', 'r') as file:
              self.dataTab = []
              self.jsonlist = json.load(file)
              self.dataTab = self.jsonlist['Test']
              print (self.jsonlist)
  
  
          self.display_table()
  </code></pre>
  <p>go to &quot;display-table&quot; a blank page with a button for launching test =&gt;</p>
  <pre><code>
   def display_table(self):
         
          self.centralwidget = QtWidgets.QWidget(self)
  
          self.menu_bar()
          self.frame_ihm()
  
          self.frame_disp = QtWidgets.QFrame(self.centralwidget)
          self.frame_disp.setGeometry(QtCore.QRect(0, 100, 1100, 40)
  
          self.newtest = QtWidgets.QPushButton(self.centralwidget)
          self.newtest.setGeometry(QtCore.QRect(1135, 300, 120, 50))
          self.newtest.setText(&quot;Launch test&quot;)
          self.newtest.clicked.connect(self.pop_up_parameters_acq)
  
          self.setCentralWidget(self.centralwidget)
  </code></pre>
  <p>use this button for launch a test =&gt; Write and Read my json =&gt;</p>
  <pre><code>def json_edit(self):
  
          self.lnapick = self.cb_lna.currentText()
          self.filterpick = self.cb_filter.currentText()
          self.polarpick = self.cb_polar.currentText()
          self.azimuthpick = self.spin_azimuth.value()
          self.acq_datetime = datetime.now().strftime(&quot;%d-%m-%Y %H:%M&quot;)
  
          self.deckfreq = []
          self.deckamp = []
  
          # 461 valeurs, ordre croissant
          for _ in range(461):
              self.deckfreq.append(random.randint(0, 25400))
          for _ in range(461):
              self.deckamp.append(random.randint(0, 100))
  
          # Ordre des valeurs aléatoires ex : 76,543,6,21890,4,67
          self.randfreq = random.shuffle(self.deckfreq)
          self.randamp = random.shuffle(self.deckamp)
  
          # Valeur min et max en fréquence
          self.freq_min = min(self.deckfreq)
          self.freq_max = max(self.deckfreq)
  
          # Ouverture json, lecture
          with open('./data/' + self.user + '_' + self.project + '_' + self.site + '.json', 'r') as f:
              parameters_projet = json.load(f)
  
              #Création dictionnaire avec data test
              test = {
                  &quot;Index&quot;: len(parameters_projet['Test'])+1,
                  &quot;Date-Time&quot;: self.acq_datetime,
                  &quot;Filter&quot;: self.filterpick,
                  &quot;LNA&quot;: self.lnapick,
                  &quot;Polarisation&quot;: self.polarpick,
                  &quot;Azimuth&quot;: self.azimuthpick,
                  &quot;Frequency min&quot;: self.freq_min,
                  &quot;Frequency max&quot;: self.freq_max,
                  &quot;Frequency&quot;: self.deckfreq,
                  &quot;Amplituds&quot;: self.deckamp,
              }
  
              #ADD information to 'Test'
              parameters_projet['Test'].append(test)
  
  
          f = open('./data/' + self.user + '_' + self.project + '_' + self.site + '.json', 'w')
         
          json_pjt = json.dumps(parameters_projet, indent=4)
          f.write(json_pjt)
  
          with open('./data/' + self.user + '_' + self.project + '_' + self.site + '.json', 'r') as file:
              self.dataTab = []
              self.jsonlist = json.load(file)
              self.dataTab = self.jsonlist['Test']
              print(self.jsonlist)
  
          self.display_table()
  
  </code></pre>
  <p>Create(or no), Up and show my Qtable in &quot;display-table&quot; with Column = keys of my json, Row = informations of my json(is already working)</p>
  <pre><code>def qtable_acq(self):
     
          self.table_widget = QtWidgets.QTableWidget(self.frame_disp)
          self.table_widget.setGeometry(QtCore.QRect(20, 100, 1100, 400))
          print(self.dataTab)
          print(len(self.dataTab))
  
          self.table_widget.setColumnCount(10)
          self.table_widget.setVisible(True)
  
  
          self.row = self.table_widget.setRowCount(len(self.dataTab))
          #rowProwosition = self.table_widget.rowCount(len(self.))
  
          i: int = 0
  
          self.table_widget.setHorizontalHeaderItem(0, QtWidgets.QTableWidgetItem(str(&quot;Test #&quot;)))
          self.table_widget.setHorizontalHeaderItem(1, QtWidgets.QTableWidgetItem(str(&quot;Link&quot;)))
          self.table_widget.setHorizontalHeaderItem(2, QtWidgets.QTableWidgetItem(str(&quot;Date - Hour&quot;)))
          self.table_widget.setHorizontalHeaderItem(3, QtWidgets.QTableWidgetItem(str(&quot;Frequency min [MHz]&quot;)))
          self.table_widget.setHorizontalHeaderItem(4, QtWidgets.QTableWidgetItem(str(&quot;Frequency max [MHz]&quot;)))
          self.table_widget.setHorizontalHeaderItem(5, QtWidgets.QTableWidgetItem(str(&quot;Polarization&quot;)))
          self.table_widget.setHorizontalHeaderItem(6, QtWidgets.QTableWidgetItem(str(&quot;Azimuth [°]&quot;)))
          self.table_widget.setHorizontalHeaderItem(7, QtWidgets.QTableWidgetItem(str(&quot;LNA&quot;)))
          self.table_widget.setHorizontalHeaderItem(8, QtWidgets.QTableWidgetItem(str(&quot;Filter&quot;)))
          self.table_widget.setHorizontalHeaderItem(9, QtWidgets.QTableWidgetItem(str(&quot;Comment&quot;)))
          self.table_widget.verticalHeader().hide()
          header = self.table_widget.horizontalHeader()
          header.setSectionResizeMode(0, QtWidgets.QHeaderView.ResizeToContents)
          header.setSectionResizeMode(1, QtWidgets.QHeaderView.ResizeToContents)
          header.setSectionResizeMode(2, QtWidgets.QHeaderView.ResizeToContents)
          header.setSectionResizeMode(3, QtWidgets.QHeaderView.ResizeToContents)
          header.setSectionResizeMode(4, QtWidgets.QHeaderView.ResizeToContents)
          header.setSectionResizeMode(5, QtWidgets.QHeaderView.ResizeToContents)
          header.setSectionResizeMode(6, QtWidgets.QHeaderView.ResizeToContents)
          header.setSectionResizeMode(7, QtWidgets.QHeaderView.ResizeToContents)
          header.setSectionResizeMode(8, QtWidgets.QHeaderView.ResizeToContents)
          header.setSectionResizeMode(9, QtWidgets.QHeaderView.Stretch)
  
          def create_acq_pop_up_callback(index):
              return lambda: self.pop_up_reading_acq(index)
  
  
          buttons_open = [QtWidgets.QPushButton(self.table_widget) for _ in range(len(self.dataTab))]
          #self.index = []
          self.filterpick =[]
          self.lnapick = []
          self.azimuthpick = []
          self.polarpick = []
          self.freq = []
          self.amp = []
          self.freq_min= []
          self.freq_max= []
          self.date_test = []
  
  
          for test in self.dataTab:
              keys = test.keys()
              self.index = test['Index']
              self.date_test.append(test['Date-Time'])
              self.freq_min.append(test['Frequency min'])
              self.freq_max.append(test['Frequency max'])
              self.filterpick.append(test['Filter'])
              self.lnapick.append(test['LNA'])
              self.azimuthpick.append(test['Azimuth'])
              self.polarpick.append(test['Polarisation'])
              self.freq.append(test['Frequency'])
              print(self.freq[self.index -1])
              self.amp.append(test['Amplituds'])
              buttons_open[self.index-1].setText(str(self.index))
              buttons_open[self.index-1].clicked.connect(create_acq_pop_up_callback(self.index))
  
              # Ajout des valeurs dans le tableau
              self.table_widget.setItem(i, 0, QtWidgets.QTableWidgetItem(str(self.index)))
              self.table_widget.setCellWidget(i, 1, buttons_open[self.index-1])
  
              self.table_widget.setItem(i, 2, QtWidgets.QTableWidgetItem(str(self.lnapick[self.index-1])))
              self.table_widget.setItem(i, 3, QtWidgets.QTableWidgetItem(str(self.freq_min[self.index-1])))
              self.table_widget.setItem(i, 4, QtWidgets.QTableWidgetItem(str(self.freq_max[self.index-1])))
              self.table_widget.setItem(i, 5, QtWidgets.QTableWidgetItem(str(self.polarpick[self.index-1])))
              self.table_widget.setItem(i, 6, QtWidgets.QTableWidgetItem(str(self.azimuthpick[self.index-1])))
              self.table_widget.setItem(i, 7, QtWidgets.QTableWidgetItem(str(self.lnapick[self.index-1])))
              self.table_widget.setItem(i, 8, QtWidgets.QTableWidgetItem(str(self.filterpick[self.index-1])))
              i = i + 1
  </code></pre>
  <p>So i really need help for this QTable apparition after pressing button in the same page and add-create automatically my columnHeader</p>
  <p>Utility of doing for me a dynamically Qtable it's, if someone want to change the code and add a new key, the Qtable will be automatically updated and added new ColumHeaderItem</p>
  <p>Sorry if i'm not really clear with my english</p>
  <p>up, show qtable when first test did
  Today, normal Qtable with colums defined at first and rows inserted with infos
  i want to see myqtable with column = ['Test].keys()
  I want automaticélly Qtable
  and insert like today row when test did</p>
  <p>Thank you</p>