Question

I'm working on an application that is using map tiles in a QGraphicsItemGroup to render a map and I want to make the switch to OpenGL so I can add 3D shapes on the map.

In order to do so as smoothly as possible I would need to get a texture from this QGraphicsItemGroup.

Was it helpful?

Solution

In case anyone has this issue I managed to get something I could work with. Rather than using the QGraphicsItemGroup I took the whole scene and made an image from it that I use as a texture.

Code extract : (map is my QGraphicsScene)

    QImage img(ui->map->width(), ui->map->height(),QImage::Format_ARGB32_Premultiplied);
    QPainter p(&img);
    ui->map->fitInView(0,0,scene.width(),scene.height(),Qt::IgnoreAspectRatio);
    ui->map->viewport()->render(&p);
    p.end();
    img.save("tmp.png");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top