Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use QPainterPath?

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)

like image 932
arthropode Avatar asked Mar 03 '26 17:03

arthropode


1 Answers

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)
like image 132
pdw Avatar answered Mar 06 '26 05:03

pdw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!