本文整理汇总了Python中PyQt4.QtSql.QSqlTableModel.setData方法的典型用法代码示例。如果您正苦于以下问题:Python QSqlTableModel.setData方法的具体用法?Python QSqlTableModel.setData怎么用?Python QSqlTableModel.setData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtSql.QSqlTableModel
的用法示例。
在下文中一共展示了QSqlTableModel.setData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setData
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import setData [as 别名]
def setData(self, index, value, role=Qt.EditRole):
"""
Custom reimplementation of the method setData.
It is necessary to work with value map and value relation.
index: column index to be set
value: value to be set
role: role used
"""
column = self.headerData(index.column(), Qt.Horizontal)
newValue = value
if self.dict.has_key(column):
if isinstance(self.dict[column], dict):
valueMap = self.dict[column]
newValue = int(valueMap[value])
elif isinstance(self.dict[column], tuple):
tupla = self.dict[column]
valueMap = self.makeValueRelationDict(tupla[0], tupla[1])
code_names = value[1:-1].split(',')
codes = []
for code_name in code_names:
code = valueMap[code_name]
codes.append(code)
if len(codes) > 0:
newValue = '{%s}' % ','.join(map(str, codes))
return QSqlTableModel.setData(self, index, newValue, role)
示例2: setData
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import setData [as 别名]
def setData(self, index, value, role=Qt.EditRole):
column = self.headerData(index.column(), Qt.Horizontal)
newValue = value
if self.dict.has_key(column):
dict = self.dict[column]
newValue = int(dict[value])
return QSqlTableModel.setData(self, index, newValue, role)
示例3: setData
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import setData [as 别名]
def setData(self, index, value, role=Qt.EditRole):
column = self.headerData(index.column(), Qt.Horizontal)
newValue = value
if self.dict.has_key(column):
if isinstance(self.dict[column], dict):
valueMap = self.dict[column]
newValue = int(valueMap[value])
elif isinstance(self.dict[column], tuple):
tupla = self.dict[column]
valueMap = self.makeValueRelationDict(tupla[0], tupla[1])
code_names = value[1:-1].split(',')
codes = []
for code_name in code_names:
code = valueMap[code_name]
codes.append(code)
if len(codes) > 0:
newValue = '{%s}' % ','.join(map(str, codes))
return QSqlTableModel.setData(self, index, newValue, role)
示例4: setData
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import setData [as 别名]
def setData(self, index, value, role):
if index.column() == 2 and role == Qt.CheckStateRole:
return QSqlTableModel.setData(self, index, QVariant('1' if value == Qt.Checked else '0'), Qt.EditRole)
return QSqlTableModel.setData(self, index, value, role)