我使用PyQt + Qt Designer并将其连接到我的PostgreSQL数据库。当我尝试使用以下代码显示数据库中的记录时:
if self.Kirurg_checkBox.isChecked():
Kirurg_query = QSqlQueryModel()
Kirurg_query.setQuery("SELECT * FROM kirurg")
global view_Kirurg
view_Kirurg = QtGui.QTableView()
view_Kirurg.setModel(Kirurg_query)
view_Kirurg.setWindowTitle('kirurg')
view_Kirurg.show()
数字列看起来像这样:2.3177e + 09,虽然看起来像他们看起来像我的数据库,如下所示:2317698765。这个工作正常,直到我改变了(在PostgreSQL内部)列类型中的字符(11)数字(11,0)(这是我的要求)。有没有办法让这些列以正常方式显示价值,而不是这个奇怪的?
修改
如果列== 0,我会把它放在一起(导致奇怪值出现的地方,但最后一列,第4列)。并且它完全删除了我的第一列(第0列),它修复了最后一列(第4列),因此它看起来很漂亮,并且它给了我很多错误行:
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
AttributeError: 'float' object has no attribute 'toString'
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\PyQt4\BazaPodataka\bazapodataka.py", line 50, in paint
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
....
....
....
他们中的更多人都是一样的。
答案 0 :(得分:1)
您可以使用QItemDelegate
格式化数据。
简短说明
在数据列索引中设置委托(在本例中为2)并将其放入QtGui.QTableView
class QCustomDelegate (QtGui.QItemDelegate):
def paint (self, painterQPainter, optionQStyleOptionViewItem, indexQModelIndex):
column = indexQModelIndex.column()
if column == 2:
textQString = '%.0f' % indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole)
# textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString() # For some version PyQt4-4.11.1-gpl-Py3.4-Qt4.8.6-x64
self.drawDisplay(painterQPainter, optionQStyleOptionViewItem, optionQStyleOptionViewItem.rect, textQString)
else:
QtGui.QItemDelegate.paint(self, painterQPainter, optionQStyleOptionViewItem, indexQModelIndex)
和
if self.Kirurg_checkBox.isChecked():
Kirurg_query = QSqlQueryModel()
Kirurg_query.setQuery("SELECT * FROM kirurg")
global view_Kirurg
view_Kirurg = QtGui.QTableView()
view_Kirurg.setItemDelegate(QCustomDelegate())
view_Kirurg.setModel(Kirurg_query)
view_Kirurg.setWindowTitle('kirurg')
view_Kirurg.show()
长解释(推荐阅读本文)
1)首先,您需要知道列中的格式数据。这是我的数据示例;
+------------+------------+-----------------+
| Name | Owner | Value |
+------------+------------+-----------------+
| Sushi | Lawson | 2.3177e+12 |
| Yakisoba | Lawson | 1.4141e+12 |
| Snack | 7-11 | 3.1446e+12 |
+------------+------------+-----------------+
好的,我想在第3列显示整数数字格式而不是指数格式。
2)在指定的列索引处设置格式。这种情况是QItemDelegate.paint (self, QPainter painter, QStyleOptionViewItem option, QModelIndex index)
中的实现的第3列到整数格式。此外,您可以自定义您想要的格式,例如xxxx.xx $等。在这种情况下,转换为字符串以便于显示整数。
class QCustomDelegate (QtGui.QItemDelegate):
def paint (self, painterQPainter, optionQStyleOptionViewItem, indexQModelIndex):
column = indexQModelIndex.column()
if column == 2:
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
self.drawDisplay(painterQPainter, optionQStyleOptionViewItem, optionQStyleOptionViewItem.rect, textQString)
else:
QtGui.QItemDelegate.paint(self, painterQPainter, optionQStyleOptionViewItem, indexQModelIndex)
3)通过方法QAbstractItemView
将QCustomDelegate
放入QAbstractItemView.setItemDelegate (self, QAbstractItemDelegate delegate)
中的QtGui.QTableView
或子类。像这样;
myQTableView = QtGui.QTableView()
myQTableView.setItemDelegate(QCustomDelegate())
最后,数据应该是这样的;
+------------+------------+-----------------+
| Name | Owner | Value |
+------------+------------+-----------------+
| Sushi | Lawson | 2317700000000 |
| Yakisoba | Lawson | 1414100000000 |
| Snack | 7-11 | 3144600000000 |
+------------+------------+-----------------+
实施例
import sys
from PyQt4 import QtCore, QtGui
class QCustomDelegate (QtGui.QItemDelegate):
def paint (self, painterQPainter, optionQStyleOptionViewItem, indexQModelIndex):
column = indexQModelIndex.column()
if column == 2:
textQString = indexQModelIndex.model().data(indexQModelIndex, QtCore.Qt.EditRole).toString()
self.drawDisplay(painterQPainter, optionQStyleOptionViewItem, optionQStyleOptionViewItem.rect, textQString)
else:
QtGui.QItemDelegate.paint(self, painterQPainter, optionQStyleOptionViewItem, indexQModelIndex)
class QCustomTreeWidget (QtGui.QTreeWidget):
def __init__(self, parent = None):
super(QCustomTreeWidget, self).__init__(parent)
self.setColumnCount(3)
self.setItemDelegate(QCustomDelegate())
def addMenu (self, name, owner, value, parentQTreeWidgetItem = None):
if parentQTreeWidgetItem == None:
parentQTreeWidgetItem = self.invisibleRootItem()
currentQTreeWidgetItem = QtGui.QTreeWidgetItem(parentQTreeWidgetItem)
currentQTreeWidgetItem.setData(0, QtCore.Qt.EditRole, name)
currentQTreeWidgetItem.setData(1, QtCore.Qt.EditRole, owner)
currentQTreeWidgetItem.setData(2, QtCore.Qt.EditRole, value)
myQApplication = QtGui.QApplication([])
myQCustomTreeWidget = QCustomTreeWidget()
myQCustomTreeWidget.addMenu('Sushi', 'Lawson', 2.3177e+012)
myQCustomTreeWidget.addMenu('Yakisoba', 'Lawson', 1.4141e+012)
myQCustomTreeWidget.addMenu('Snack', '7-11', 3.1446e+012)
myQCustomTreeWidget.show()
sys.exit(myQApplication.exec_())