Table view
In the preceding sections, we discussed various model classes. Now, we will look at how to present the data to the users using the QTableView
widget. The data source for the QTableView
is provided by any of the model classes. The table view is the most used view format as this represents a virtual representation of 2D SQL table structure. We will look at the code first, then discuss its functionality:
import sys from PySide.QtGui import * from PySide.QtCore import * from PySide.QtSql import * def initializeModel(model): model.setTable("employee") model.setEditStrategy(QSqlTableModel.OnManualSubmit) model.select() model.setHeaderData(0, Qt.Horizontal, "ID") model.setHeaderData(1, Qt.Horizontal, "First Name") model.setHeaderData(2, Qt.Horizontal, "Last Name") model.setHeaderData(3, Qt.Horizontal, "Age") model.setHeaderData(4, Qt.Horizontal, "Gender") model.setHeaderData(5, Qt.Horizontal, "Income") def createView(title, model): view = QTableView...