PDA

View Full Version : capturing a QDeclarativeItem into a QPixmap



ugluk
7th May 2012, 12:01
I am trying to capture a QDeclarativeItem into a QPixmap to drag it interactively:



{
QObject* obj;
draggedPixmap = QPixmap(qobject_cast<QGraphicsItem*>(obj)->
boundingRect().size().toSize());

QPainter painter(&draggedPixmap);

QStyleOptionGraphicsItem option;

QPointF p(QCursor::pos());

qobject_cast<QGraphicsItem*>(obj)->paint(&painter, &option);

drag->setPixmap(draggedPixmap);
}


The problem is, that not all children of the QDeclarativeItem will paint into the QPixmap (say, text won't show up in the QPixmap, but Rectangles will). Calling paint on the Text QDeclarativeItem directly produces garbage. Should I be capturing into a QImage?

Added after 36 minutes:

The answer: call GraphicsView::render()!