from PySide2.QtWidgets import QTableWidgetItem, QTableWidget # create a QTableWidget object table_widget = QTableWidget() # create a QTableWidgetItem object and set its text item_1 = QTableWidgetItem() item_1.setText("Hello, world!") # add the QTableWidgetItem object to the first cell of the third row table_widget.setItem(2, 0, item_1)
from PySide2.QtWidgets import QTableWidgetItem, QTableWidget # create a QTableWidget object table_widget = QTableWidget() # create a list of data to populate the table data = [("Alice", "Smith", 25), ("Bob", "Jones", 32), ("Charlie", "Brown", 41)] # set the number of rows and columns in the table table_widget.setRowCount(len(data)) table_widget.setColumnCount(3) # populate the table with data for row, item in enumerate(data): for col, content in enumerate(item): cell_item = QTableWidgetItem() cell_item.setText(str(content)) table_widget.setItem(row, col, cell_item)This example creates a new QTableWidget object and populates it with data from a list. The setText method is used to set the text content of each cell in the table. Package library: PySide2.