最近切换到Pyqt6数据库,搞不清这个枚举类型的值:
model.setEditStrategy(QtSql.QSqlTableModel.OnFieldChange)
我试过了:
- 传入枚举类型的数值即0。解释器抱怨说它不能接受int类型。
有没有人想出新的价值应该是什么?有没有办法让我或其他人自己找出来?
from PyQt6.QtWidgets import QMessageBox, QApplication, QTableView, QVBoxLayout, QPushButton, QWidget
from PyQt6.QtSql import QSqlDatabase, QSqlTableModel
from PyQt6 import QtCore
from PyQt6 import QtSql
def initializeModel(model):
model.setTable('authors1')
model.setEditStrategy(QtSql.QSqlTableModel.OnFieldChange)
model.select()
model.setHeaderData(1, QtCore.Qt.Orientations.Horizontal, 'Author name(s)')
def createView(model):
view = QTableView()
view.setModel(model)
view.resize(230, 254)
view.hideColumn(0)
view.setColumnWidth(1, 200)
return view
def addRecord():
sqm.insertRow(sqm.rowCount())
def delRecord() :
sqm.removeRow(view1.currentIndex().row())
sqm.select()