【发布时间】:2015-07-03 06:10:55
【问题描述】:
我想在不绘制场景的情况下将项目绘制到 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
如何使用项目的绘制方法将单个项目仅渲染到 QPixmap ?
我认为的替代方案是在项目矩形上创建另一个 QGraphicsView,然后渲染它,但我认为这会产生太多开销......
【问题讨论】:
-
#include
可能会修复您遇到的编译错误。 -
您可能还需要#include
-
感谢没有更多的错误! (就在我用 update() 的调用替换了油漆时):-)
-
请回答...
标签: c++ image qt qgraphicsitem qpainter