Vlad
Vlad

Reputation: 419

Is there any easy way to draw complicated things with QPainterPath or using similar thing in PyQt

I am learning right now PyQt and especially QGraphicsScene. Right now , I am trying to draw some complicated things , like for example 'human hand' , but I find QPainterPath is a little bit complicated. What can you advice ? Maybe using some openGL or some Photoshop import pictures? I am also a little bit worrying about speed, I would appreciate answers which will take in account that factor. Will put example of drawing I want to achieve. Thank you

enter image description here

Upvotes: 1

Views: 68

Answers (1)

eyllanesc
eyllanesc

Reputation: 244003

If you want to implement complicated things then create an image as you save time.

enter image description here

from PySide2 import QtCore, QtGui, QtWidgets

if __name__ == "__main__":
    import sys

    app = QtWidgets.QApplication(sys.argv)
    scene = QtWidgets.QGraphicsScene(backgroundBrush=QtCore.Qt.gray)
    w = QtWidgets.QGraphicsView(scene)
    pixmap = QtGui.QPixmap("hand128.png")
    pixmap_item = QtWidgets.QGraphicsPixmapItem(pixmap)
    pixmap_item.setFlags(
        pixmap_item.flags()
        | QtWidgets.QGraphicsItem.ItemIsSelectable
        | QtWidgets.QGraphicsItem.ItemIsMovable
    )
    scene.addItem(pixmap_item)
    w.show()
    sys.exit(app.exec_())

enter image description here

Upvotes: 2

Related Questions