Здравствуйте, помогите пожалуйста. При выполнении значения передаются из списка в таблицу. Сама таблица создается правильно но в ячейках таблицы не видно значений. С чем это может быть связано?? (полностью программа
https://drive.google.com/drive/folders/0B9z4hazqmUVAamNzZk85ZjJ0ekU?usp=sharing )
#!usr/bin/python3.4
# -*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui
import form, sys
class MyWindow(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = form.Ui_Form()
self.ui.setupUi(self)
self.connect(self.ui.pushButton, QtCore.SIGNAL("clicked()"), self.clickedButton)
def clickedButton(self):
data=[
['cell11','cell12','cell13','cell14','cell15','cell16',],
['cell21','cell22','cell23','cell24','cell25','cell26',],
['cell31','cell32','cell33','cell34','cell35','cell36',],
['cell41','cell42','cell43','cell44','cell45','cell46',],
['cell51','cell52','cell53','cell54','cell55','cell56',],
['cell61','cell62','cell63','cell64','cell65','cell66',],
['cell71','cell72','cell73','cell74','cell75','cell76',],
['cell81','cell82','cell83','cell84','cell85','cell86',],
]
self.ui.label.setText("<font color=green><b>Результаты поиска<b>")
self.myModel = form.Model(data)
self.ui.tableView.setModel(self.myModel)
self.ui.tableView.resizeRowsToContents()
self.ui.tableView.resizeColumnsToContents()
def main():
app = QtGui.QApplication(sys.argv)
window = MyWindow()
window.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
conn.close()
файлик form
#!usr/bin/python3.4
# -*- coding: utf-8 -*-
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Model(QtCore.QAbstractTableModel):
colLabels = ['Обозначение','Наименование','Статус','Заменен','Взамен','Перевод наименования']
def __init__(self, datain, parent=None, *args):
QtCore.QAbstractTableModel.__init__(self, parent, *args)
self.gui = parent
self.cached = datain
def rowCount(self, parent):
return len(self.cached)
def columnCount(self, parent):
return len(self.cached[0])
def data(self, index, role):
if index.isValid():
return None
elif role !=QtCore.Qt.DisplayRole:
return None
value=''
if role == QtCore.Qt.DisplayRole:
row = index.row()
col = index.column()
value=str(self.cached[index.row()][index.column()])
return value
def flags(self, index):
if not index.isValid():
return QtCore.Qt.ItemIsEnabled
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEditable
def setData(self, index, value, role):
if index.isValid() and role == QtCore.Qt.EditRole:
self.cached[index.row()][index.column()] = QtCore.QVariant(value)
self.emit(QtCore.SIGNAL("dataChanged(QModelIndex, QModelIndex)"), index, index)
return True
else:
return False
def headerData(self, section, orientation, role):
if role == QtCore.Qt.DisplayRole:
if orientation == QtCore.Qt.Horizontal:
return self.colLabels[section]
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(1111, 781)
font = QtGui.QFont()
font.setPointSize(8)
Form.setFont(font)
self.verticalLayout = QtGui.QVBoxLayout(Form)
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.lineEdit = QtGui.QLineEdit(Form)
font = QtGui.QFont()
font.setPointSize(12)
self.lineEdit.setFont(font)
self.lineEdit.setObjectName(_fromUtf8("lineEdit"))
self.horizontalLayout.addWidget(self.lineEdit)
self.pushButton = QtGui.QPushButton(Form)
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.pushButton.setAutoDefault(True)
self.horizontalLayout.addWidget(self.pushButton)
self.verticalLayout.addLayout(self.horizontalLayout)
self.label = QtGui.QLabel(Form)
font = QtGui.QFont()
font.setPointSize(10)
self.label.setFont(font)
self.label.setLocale(QtCore.QLocale(QtCore.QLocale.Russian, QtCore.QLocale.Ukraine))
self.label.setObjectName(_fromUtf8("label"))
self.verticalLayout.addWidget(self.label)
self.tableView = QtGui.QTableView(Form)
self.tableView.setObjectName(_fromUtf8("tableView"))
self.verticalLayout.addWidget(self.tableView)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Global Search", None))
self.pushButton.setText(_translate("Form", "Поиск", None))
self.label.setText(_translate("Form", "Введите Ваш запрос", None))