2014-09-05 3 views
0

저는 PyQt + Qt Designer를 사용하고 있으며 이것을 PostgreSQL 데이터베이스에 연결했습니다. 이 코드 내 데이터베이스에서 레코드를 표시 할 때 : 그들은이 같은 내 데이터베이스에 보이는 것처럼 그들이 보게해야하지만, 2.3177e + 09 :숫자 형식이 이상한 형태로 표시됩니다.

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

숫자 열은 다음과 같이 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 형식의 열 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.setItemDelegate (self, QAbstractItemDelegate delegate)에 의해 QAbstractItemViewQtGui.QTableView 또는 서브 클래스에 QCustomDelegate. 이것 같이;

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

+0

'indexQModelIndex.model(). data (indexQModelIndex, QtCore.Qt.EditRole)'의 Meybe 반환 값은 float 데이터 유형 ('QVariant'가 아님)입니다. 좋아, 문자열로 변환하십시오.편집 게시물을 확인하십시오. 나는 질문이있다, 당신 PyQt 버전은 무엇입니까? 감사. –

+1

이제 작동 중입니다! 당신은 다시 한번 생명의 은인입니다. :) PyQt4,이 버전을 사용하고 있습니다 : PyQt4-4.11.1-gpl-Py3.4-Qt4.8.6-x64.exe. 한가지 더 물어 보겠습니다. 나는 column == 2를 넣었고, 그것이 모든 숫자 열에 대해 작동하는 이유는 무엇입니까? 예를 들어 ID 열 (열 0) 및 전화 번호 열 (열 4)에서 작동합니까? – Luka

관련 문제