Created
December 13, 2012 10:34
-
-
Save dokinkon/4275597 to your computer and use it in GitHub Desktop.
QGraphicsItem to QPixmap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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