2016-12-24 118 views
0

我試圖畫靜態文本,但得到錯誤,你能解釋我做錯了什麼,爲什麼NoneType?drawStaticText給出了錯誤

這裏是代碼:

sT = QtGui.QStaticText() 
text = 'text' 
painter.drawStaticText(QtCore.QPoint(40, 50), sT.setText(text)) 

和錯誤:

painter.drawStaticText(QtCore.QPoint(40, 50), staticT.setText(text)) 
TypeError: arguments did not match any overloaded call: 
QPainter.drawStaticText(QPointF, QStaticText): argument 2 has unexpected type 'NoneType' 
QPainter.drawStaticText(QPoint, QStaticText): argument 2 has unexpected type 'NoneType' 
QPainter.drawStaticText(int, int, QStaticText): argument 1 has unexpected type 'QPoint' 

謝謝。

+0

我認爲你必須在兩個步驟 - 第一個'sT.setText(文本)'和以後'drawStaticText(QtCore.QPoint(40,50),sT)' – furas

回答

1

我認爲你有兩個步驟

sT.setText(text) 
painter.drawStaticText(QtCore.QPoint(40, 50), sT) 

因爲sT.setText(text)回報None,不QStaticText對象做。

+0

謝謝你和聖誕節結婚!現在我得到了這個:) –