gpt4 book ai didi

c++ - 在 QPixmap : aggregate 'QWidget w' has incomplete type and cannot be defined 上渲染 QGraphicsItem

转载 作者:行者123 更新时间:2023-11-28 06:18:08 25 4
gpt4 key购买 nike

我想在不绘制场景的情况下将项目绘制到 QPixmap 中......

我试过了,基于this :

void Item::itemPaint(QPainter *painter)
{
QStyleOptionGraphicsItem opt;
QWidget w;
paint(painter, &opt, &w); // also tried NULL
}

void Item::paint(QPainter *painter, const QStyleOptionGraphicsItem */*option*/, QWidget */*widget*/)
{
....
}


void caller()
{
QPainter* painter;
for(int i = 0; i< collectionView->scene()->items().size(); i++)
{
QGraphicsItem* qitem = collectionView->scene()->items().at(i);
Item* item = new Item(*(dynamic_cast<Item*>(qitem)));
QPixmap pItem(item->boundingRect().size().toSize());
pItem.fill(QColor(Qt::color0).rgb());
painter = new QPainter(&pItem);
painter->setRenderHint(QPainter::Antialiasing);
item->itemPaint(painter);
painter->end();
}
}

我明白了

error: aggregate 'QStyleOptionGraphicsItem opt' has incomplete type and cannot be defined
error: aggregate 'QWidget w' has incomplete type and cannot be defined

如何使用项目的 paint 方法将单个项目仅渲染到 QPixmap ?

我认为替代方案是在项目矩形上创建另一个 QGraphicsView,然后渲染它,但我认为这会产生太多开销...

最佳答案

#include <QWidget>#include <QStyleOptionGraphicsItem>应该修复您遇到的编译错误。

关于c++ - 在 QPixmap : aggregate 'QWidget w' has incomplete type and cannot be defined 上渲染 QGraphicsItem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29850872/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com