Issue
I have the following test code:
import sys
from PySide.QtGui import *
app = QApplication(sys.argv)
widget = QWidget()
painter = QPainter(widget)
Upon creating the QPainter object, I get the error message:
QPainter::begin: Paint device returned engine == 0, type: 1
Why?
Solution
If you want to draw something inside a widget, you need to use the paintEvent
of the widget to define a QPainter
. This method allows to declare a Qpainter
for an immediat painting, and by the way it avoids a call to Qpainter.begin()
and Qpainter.end()
.
class MyWidget(QWidget):
def __init__(self):
super().__init__()
def paintEvent(self, event):
painter = QPainter(self)
painter.drawLine(0, 0, 100, 100)
app = QApplication(sys.argv)
widget = MyWidget()
widget.show()
sys.exit(app.exec_())
http://doc.qt.io/qt-5/qpainter.html#details
Warning: When the paintdevice is a widget, QPainter can only be used inside a paintEvent() function or in a function called by paintEvent().
Answered By - PRMoureu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.