I would like to paint items into QPixmap without painting the scene...
I tried, based on 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();
}
}
I get
error: aggregate 'QStyleOptionGraphicsItem opt' has incomplete type and cannot be defined
error: aggregate 'QWidget w' has incomplete type and cannot be defined
How can I use the item's paint method to render the single item only to a QPixmap ?
The alternative I think would be to create ANOTHER QGraphicsView on the item rectangle, and render that, but I think that would be too much overhead...
#include <QWidget>
and #include <QStyleOptionGraphicsItem>
should fix the compile error you are getting.