我想将项目绘制到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
如何使用item的paint方法将单个项目仅渲染到QPixmap?
我认为替代方案是在项目矩形上创建另一个QGraphicsView,并渲染它,但我认为这将是太多的开销......
答案 0 :(得分:1)
#include <QWidget>
和#include <QStyleOptionGraphicsItem>
应修复您遇到的编译错误。