区切り文字の行を持つテキストエディットウィジェットを作成しようとしています。まず、MyTextEdit
クラスを(のサブクラスとして)作成し、そのメソッドQTextEdit
をオーバーライドしました。paintEvent()
import sys
from PyQt4.QtGui import QApplication, QTextEdit, QPainter
class MyTextEdit(QTextEdit):
"""A TextEdit widget derived from QTextEdit and implementing its
own paintEvent"""
def paintEvent(self, event):
painter = QPainter(self)
painter.drawLine(0, 10, 10, 10)
QTextEdit.paintEvent(self, event)
app = QApplication(sys.argv)
textEdit = MyTextEdit()
textEdit.show()
sys.exit(app.exec_())
このコードを実行しようとすると、次のエラーがたくさん発生します。
QPainter::begin: Widget painting can only begin as a result of a paintEvent
QPainter::begin: Widget painting can only begin as a result of a paintEvent
...
私は何が間違っているのですか?