I'm using pyqt to try to create an application which display images and curves.
To draw bezier curves, I found the QPainterPath class and specifically QpainterPath.cubicTo. However, I don't understand how this class must be used. In which widget should I draw my curves?
I see there are Qpainter and QGraphicsView/QGraphicsScene, but I don't know how to use my QPainterPath with them.
Do you have any example of the use of QPainterPath with pyqt/pyside? (for example, a simple window which displays a cubic bezier curve)
QPainter is a pretty low-level class. For simple applications you can ignore it. Add a QGraphicsView widget and do something like this:
# Prepare the QGraphicsView widget
scene = QtGui.QGraphicsScene(graphicsView)
graphicsView.setScene(scene)
graphicsView.setRenderHint(QtGui.QPainter.Antialiasing)
# Draw a line
path = QtGui.QPainterPath()
path.moveTo(0, 0)
path.cubicTo(100, -20, 40, 90, 20, 20)
scene.addPath(path)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With