Postgresql 以奇怪形式显示的数字类型

Postgresql 以奇怪形式显示的数字类型,postgresql,pyqt,qt-designer,Postgresql,Pyqt,Qt Designer,我正在使用PyQt+Qt设计器,并已将其连接到我的PostgreSQL数据库。当我尝试使用以下代码显示数据库中的记录时: if self.Kirurg_checkBox.isChecked(): Kirurg_query = QSqlQueryModel() Kirurg_query.setQuery("SELECT * FROM kirurg") global view

我正在使用PyQt+Qt设计器,并已将其连接到我的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)(这是我所必需的)之前,这种方法工作得很好。有没有办法让这些列以正常的方式显示值,而不是这种奇怪的方式

编辑:

我将if列==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()
....
....
....
并将它们聚在一起,所有这些都是一样的。

您可以使用它们来格式化数据

简短解释

在数据列索引中设置委托(在本例中为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)


详细解释(建议阅读此)

1) 首先,您需要知道列中的格式化数据是什么。这是我的数据示例

+------------+------------+-----------------+
|    Name    |   Owner    |      Value      |
+------------+------------+-----------------+
| Sushi      | Lawson     |      2.3177e+12 |
| Yakisoba   | Lawson     |      1.4141e+12 |
| Snack      | 7-11       |      3.1446e+12 |
+------------+------------+-----------------+
好的,我想在第3列显示整数格式,而不是指数格式

2) 在指定的列索引处设置格式。本例是第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) 将
QCustomDelegate
放到
QtGui.QTableView
或子类中的by方法。像这样,

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_())

Meybe返回的
indexQModelIndex.model().data(indexQModelIndex,QtCore.Qt.EditRole)
是浮点数据类型(不是
QVariant
)。好的,把它转换成字符串。查看我的编辑帖子。我有个问题,你的PyQt版本是什么?谢谢,现在开始工作了!你是救命恩人,再一次:)。我使用的是PyQt4,这个版本:PyQt4-4.11.1-gpl-Py3.4-Qt4.8.6-x64.exe。我再问你一件事。我把if column==2,它对我所有的数字列都有效,为什么?例如,它适用于“我的ID”列(第0列)和“我的电话号码”列(第4列)?因为在标准视图中显示自定义模型中的项目。默认显示为字符串值或指数格式值。处于
QItemDelegate
的机制中。或者简单地说,我们创建自定义显示数据,默认情况下所有数据都将显示字符串格式。
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_())