Skip to content

Instantly share code, notes, and snippets.

@dokinkon
Created December 13, 2012 10:34
Show Gist options
  • Save dokinkon/4275597 to your computer and use it in GitHub Desktop.
Save dokinkon/4275597 to your computer and use it in GitHub Desktop.
QGraphicsItem to QPixmap
QPixmap GraphicsItem::toPixmap() const
{
if (!scene()) {
qWarning() << "[ControlItem::toPixmap] scene is null.";
return QPixmap();
}
QRectF r = boundingRect();
QPixmap pixmap(r.width(), r.height());
pixmap.fill(QColor(0, 0, 0, 0));
QPainter painter(&pixmap);
//painter.setBrush(QBrush(QColor(0, 0, 0, 0)));
painter.drawRect(r);
scene()->render(&painter, QRectF(), sceneBoundingRect());
painter.end();
return pixmap;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment