有没有简单的方法来使用QPainterPath绘制复杂的东西或在PyQt中使用类似的东西

问题描述 投票:1回答:1

我正在学习PyQt,尤其是QGraphicsScene。现在,我试图绘制一些复杂的东西,例如'人手',但我发现QPainterPath有点复杂。你有什么建议吗?也许使用一些openGL或一些Photoshop导入图片?我也有点担心速度,我会很感激将考虑到这个因素的答案。将我想要实现的绘图示例。谢谢

enter image description here

python pyqt
1个回答
2
投票

如果你想实现复杂的东西,那么在节省时间的同时创建一个图像。

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

© www.soinside.com 2019 - 2024. All rights reserved.