2014-09-05 43 views
0

我使用的是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() 
.... 
.... 
.... 

和一大堆更多的人,所有的相同。

回答

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 | 
+------------+------------+-----------------+ 

OK,我想告訴整數格式的第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)把你QCustomDelegateQAbstractItemViewQtGui.QTableView或子類的方法QAbstractItemView.setItemDelegate (self, QAbstractItemDelegate delegate)。喜歡這個;

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

我修改了我的帖子。 – Luka 2014-09-06 10:46:23

+0

'indexQModelIndex.model().method(indexQModelIndex,QtCore.Qt.EditRole)'的Meybe返回值是float數據類型(不是'QVariant')。好的,把它轉換成字符串。檢查我的編輯帖子。我有問題,你的PyQt版本是什麼?謝謝。 – 2014-09-06 17:36:39

+1

它現在正在工作!你是拯救者,再一次:)。我使用PyQt4,這個版本:PyQt4-4.11.1-gpl-Py3.4-Qt4.8.6-x64.exe。讓我再問你一件事。我已經把如果列== 2,並且它適用於我所有的數字列,爲什麼?例如,它適用於我的ID列(第0列)和我的電話號碼列(第4列)? – Luka 2014-09-06 21:28:23