要在已有的 QGraphicsPixmapItem 上添加另一个 QGraphicsPixmapItem,可以按照以下步骤进行:

  1. 创建第一个 QGraphicsPixmapItem 对象,设置其图像和位置。
QPixmap pixmap('image1.png');
QGraphicsPixmapItem* item1 = new QGraphicsPixmapItem(pixmap);
item1->setPos(x1, y1); // 设置第一个 item 的位置
  1. 创建第二个 QGraphicsPixmapItem 对象,设置其图像和位置。
QPixmap pixmap2('image2.png');
QGraphicsPixmapItem* item2 = new QGraphicsPixmapItem(pixmap2);
item2->setPos(x2, y2); // 设置第二个 item 的位置
  1. 将第二个 QGraphicsPixmapItem 对象添加到第一个 QGraphicsPixmapItem 对象的父项中。
item1->addToGroup(item2);

这样,第二个 QGraphicsPixmapItem 对象就会被添加到第一个 QGraphicsPixmapItem 对象的位置上。

Qt QGraphicsPixmapItem叠加:如何在已有图像上添加另一个图像