我正在学习PyQt,尤其是QGraphicsScene。现在,我试图绘制一些复杂的东西,例如'人手',但我发现QPainterPath有点复杂。你有什么建议吗?也许使用一些openGL或一些Photoshop导入图片?我也有点担心速度,我会很感激将考虑到这个因素的答案。将我想要实现的绘图示例。谢谢
如果你想实现复杂的东西,那么在节省时间的同时创建一个图像。
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_())