Dup Ver Goto 📝

TableWidget_01

To
37 lines, 84 words, 904 chars Page 'TableWidget_01' does not exist.
from PySide6.QtWidgets import QMainWindow, QVBoxLayout, QTableWidget, QTableWidgetItem, QApplication, QWidget
app = QApplication()
import random

# table example
class TableExample(QMainWindow):
  def __init__(self):
    super().__init__()
    table = QTableWidget()
    table.setRowCount(16)
    table.setColumnCount(8)
    table.setHorizontalHeaderLabels([str(x) for x in range(8)])
    self.table = table

    self.randomize()

    layout = QVBoxLayout()
    layout.addWidget(table)

    container = QWidget()
    container.setLayout(layout)

    self.setCentralWidget(container)

  def randomize(self):
    table = self.table
    data = [ [ random.randrange(128) for x in range(8) ] for y in range(16) ]
    for i, xs in enumerate(data):
      for j, y in enumerate(xs):
        table.setItem(i,j,QTableWidgetItem(str(y)))
    self.update()

window = TableExample()
window.show()
app.exec()