我试图绘制静态文本但得到错误,你能解释我做错了什么,为什么是NoneType?
这是代码:
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 :(得分:1)
我认为你必须分两步完成
sT.setText(text)
painter.drawStaticText(QtCore.QPoint(40, 50), sT)
因为sT.setText(text)
返回None
,而不是QStaticText
对象。