So I’ve got this case where I’m rendering a QML Item into a pixmap to be used as the source of an Image {} in the view to do some magic.. so my setup is that I’ve got an object to grab the item into QPixmap and another as QDeclarativeImageProvider to provide that bitmap into an Image. The following code grabs an item:
void Capture::save(QDeclarativeItem* item)
{
delete m_pixmap;
m_pixmap = NULL;
m_pixmap = new QPixmap(item->width(), item->height());
QPainter painter(m_pixmap);
QStyleOptionGraphicsItem option;
item->paint(&painter, &option, NULL);
}
..but the problem is that only the top-level Item is rendered and none of its children. Say I have this QML:
Item {
id: root
Rectangle {
id: fooRect
width: parent.width
height: parent.height
gradient: Gradient {
GradientStop { position: 0.0; color: "#8888FF" }
GradientStop { position: 1.0; color: "#8888AA" }
}
Text {
id: pageHeader
text: qsTr("View 1")
anchors.top: parent.top
anchors.left: parent.left
font.pixelSize: 40
color: "white"
}
}
function grab() {
capture.save(fooRect);
}
}
After grab() the pixmap would contain the gradient from the fooRect but not the text from pageHeader.
Now, I obviously can recurse into QGraphicsItem::childItems() breadth-first and render all children manually, but this will require dabbling with the hierarchial transforms. So, there must be an easier way. What is it? :D
- Matti
↧