本文整理汇总了Python中PyQt4.QtSql.QSqlTableModel.data方法的典型用法代码示例。如果您正苦于以下问题:Python QSqlTableModel.data方法的具体用法?Python QSqlTableModel.data怎么用?Python QSqlTableModel.data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtSql.QSqlTableModel
的用法示例。
在下文中一共展示了QSqlTableModel.data方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: data
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import data [as 别名]
def data(self, index, role=Qt.DisplayRole):
if not index.isValid():
return QVariant()
column = index.column()
if role == Qt.DisplayRole:
if column == DATAINS:
return QVariant(QSqlTableModel.data(self,
index).toDate().toString(DATEFORMAT))
if column == IMP:
return QVariant("€ %s" %
QSqlTableModel.data(self, index).toString())
if role == Qt.TextAlignmentRole:
if column == DATAINS:
return QVariant(int(Qt.AlignLeft|Qt.AlignVCenter))
else:
return QVariant(int(Qt.AlignRight|Qt.AlignVCenter))
if role == Qt.BackgroundRole:
if column == QT:
if QSqlTableModel.data(self, index).toInt()[0] == 0:
return QVariant(QColor(Qt.red))
# default, no specific condition found
return QSqlTableModel.data(self, index, role)
示例2: data
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import data [as 别名]
def data(self, index, role):
"""
Custom reimplementation of the method data.
It is necessary to work with value map and value relation.
index: column index
role: role used to get the data
"""
dbdata = QSqlTableModel.data(self, index, role)
column = self.headerData(index.column(), Qt.Horizontal)
if self.dict.has_key(column):
if isinstance(self.dict[column], dict):
valueMap = self.dict[column]
if str(dbdata) in valueMap.values():
id = valueMap.values().index(str(dbdata))
return valueMap.keys()[id]
elif isinstance(self.dict[column], tuple):
tupla = self.dict[column]
valueMap = self.makeValueRelationDict(tupla[0], tupla[1])
codes = str(dbdata)[1:-1].split(',')
code_names = list()
for c in codes:
if str(c) in valueMap.values():
id = valueMap.values().index(str(c))
code_name = valueMap.keys()[id]
code_names.append(code_name)
if len(code_names) > 0:
return '{%s}' % ','.join(code_names)
return dbdata
示例3: get_color_by_option
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import data [as 别名]
def get_color_by_option(self, index):
option = QSqlTableModel.data(self, self.index(index.row(), 3)).toString()
if option == 'left':
return QColor(Qt.darkGreen)
if option == 'right':
return QColor(Qt.darkCyan)
return QVariant()
示例4: data
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import data [as 别名]
def data(self, index, role):
if role == Qt.FontRole:
return self.font
if role == Qt.TextAlignmentRole:
return Qt.AlignCenter
if role == Qt.BackgroundColorRole:
return self.get_color_by_option(index)
if index.column() == 2:
value = QSqlTableModel.data(self, index, Qt.EditRole).toInt()[0] == 1
if role == Qt.CheckStateRole:
return Qt.Checked if value else Qt.Unchecked
if role == Qt.EditRole or role == Qt.DisplayRole:
return QVariant(value)
return QVariant()
return QSqlTableModel.data(self, index, role)
示例5: data
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import data [as 别名]
def data(self, index, role=Qt.DisplayRole):
if not index.isValid():
return QVariant()
column = index.column()
if role == Qt.DisplayRole:
if column == SIMP:
return QVariant("€ %.2f" %
QSqlTableModel.data(self, index).toDouble()[0])
elif column == SIVA:
return QVariant("%.2f %%" %
QSqlTableModel.data(self, index).toDouble()[0])
if role == Qt.TextAlignmentRole:
return QVariant(int(Qt.AlignRight|Qt.AlignVCenter))
# default, no specific condition found
return QSqlTableModel.data(self, index, role)
示例6: data
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import data [as 别名]
def data(self, index, role):
code = QSqlTableModel.data(self, index, role)
column = self.headerData(index.column(), Qt.Horizontal)
if self.dict.has_key(column):
dict = self.dict[column]
if str(code) in dict.values():
id = dict.values().index(str(code))
return dict.keys()[id]
return code
示例7: data
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import data [as 别名]
def data(self, index, role):
dbdata = QSqlTableModel.data(self, index, role)
column = self.headerData(index.column(), Qt.Horizontal)
if self.dict.has_key(column):
if isinstance(self.dict[column], dict):
valueMap = self.dict[column]
if str(dbdata) in valueMap.values():
id = valueMap.values().index(str(dbdata))
return valueMap.keys()[id]
elif isinstance(self.dict[column], tuple):
tupla = self.dict[column]
valueMap = self.makeValueRelationDict(tupla[0], tupla[1])
codes = str(dbdata)[1:-1].split(',')
code_names = list()
for c in codes:
if str(c) in valueMap.values():
id = valueMap.values().index(str(c))
code_name = valueMap.keys()[id]
code_names.append(code_name)
if len(code_names) > 0:
return '{%s}' % ','.join(code_names)
return dbdata
示例8: MainWindow
# 需要导入模块: from PyQt4.QtSql import QSqlTableModel [as 别名]
# 或者: from PyQt4.QtSql.QSqlTableModel import data [as 别名]
class MainWindow(QMainWindow, magazzino_ui.Ui_MainWindow):
FIRST, PREV, NEXT, LAST = range(4)
Clipboard = [] # lista di oggetti
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
self.setupMenu()
self.restoreWinSettings()
self.editindex = None
self.filename = None
self.db = QSqlDatabase.addDatabase("QSQLITE")
self.loadInitialFile()
self.setupUiSignals()
def keyPressEvent(self, event):
if event.key() == Qt.Key_Down:
self.addDettRecord()
else:
QMainWindow.keyPressEvent(self, event)
def creaStrutturaDB(self):
query = QSqlQuery()
if not ("magamaster" in self.db.tables()):
if not query.exec_("""CREATE TABLE magamaster (
id INTEGER PRIMARY KEY AUTOINCREMENT
UNIQUE NOT NULL,
scaff VARCHAR(10) NOT NULL)"""):
QMessageBox.warning(self, "Magazzino",
QString("Creazione tabella fallita!"))
return False
if not ("magaslave" in self.db.tables()):
if not query.exec_("""CREATE TABLE magaslave (
id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL,
datains DATE NOT NULL,
abbi VARCHAR(50),
angro VARCHAR(50),
desc VARCHAR(100),
qt INTEGER NOT NULL DEFAULT '1',
imp DOUBLE NOT NULL DEFAULT '0.0',
equiv VARCHAR(100),
mmid INTEGER NOT NULL,
fatt VARCHAR(50),
note VARCHAR(200),
FOREIGN KEY (mmid) REFERENCES magamaster)"""):
QMessageBox.warning(self, "Magazzino",
QString("Creazione tabella fallita!"))
return False
QMessageBox.information(self, "Magazzino",
QString("Database Creato!"))
return True
def loadFile(self, fname=None):
if fname is None:
return
if self.db.isOpen():
self.db.close()
self.db.setDatabaseName(QString(fname))
if not self.db.open():
QMessageBox.warning(self, "Magazzino",
QString("Database Error: %1")
.arg(self.db.lastError().text()))
else:
if not self.creaStrutturaDB():
return
self.filename = unicode(fname)
self.setWindowTitle("Gestione Magazzino - %s" % self.filename)
self.setupModels()
self.setupMappers()
self.setupTables()
#self.setupItmSignals()
self.restoreTablesSettings()
self.mmUpdate()
def loadInitialFile(self):
settings = QSettings()
fname = unicode(settings.value("Settings/lastFile").toString())
if fname and QFile.exists(fname):
self.loadFile(fname)
def openFile(self):
dir = os.path.dirname(self.filename) \
if self.filename is not None else "."
fname = QFileDialog.getOpenFileName(self,
"Gestione Magazzino - Scegli database",
dir, "*.db")
if fname:
self.loadFile(fname)
def newFile(self):
dir = os.path.dirname(self.filename) \
#.........这里部分代码省略.........