Qt QGraphicsPixmapItem叠加:如何在已有图像上添加另一个图像
要在已有的 QGraphicsPixmapItem 上添加另一个 QGraphicsPixmapItem,可以按照以下步骤进行:
- 创建第一个 QGraphicsPixmapItem 对象,设置其图像和位置。
QPixmap pixmap('image1.png');
QGraphicsPixmapItem* item1 = new QGraphicsPixmapItem(pixmap);
item1->setPos(x1, y1); // 设置第一个 item 的位置
- 创建第二个 QGraphicsPixmapItem 对象,设置其图像和位置。
QPixmap pixmap2('image2.png');
QGraphicsPixmapItem* item2 = new QGraphicsPixmapItem(pixmap2);
item2->setPos(x2, y2); // 设置第二个 item 的位置
- 将第二个 QGraphicsPixmapItem 对象添加到第一个 QGraphicsPixmapItem 对象的父项中。
item1->addToGroup(item2);
这样,第二个 QGraphicsPixmapItem 对象就会被添加到第一个 QGraphicsPixmapItem 对象的位置上。
AI 优化版
原文地址:https://www.cveoy.top/t/topic/qA3v 著作权归作者所有。请勿转载和采集!