QGraphicsSvg
-
hi,
I'm loading a complete SVG file to graphicsView.
Below is the code which is working fine.
QGraphicsScene *scene = new QGraphicsScene();
QGraphicsSvgItem *item = new QGraphicsSvgItem("C://svg//deckmain.svg");
scene->addItem(item);
scene->setBackgroundBrush(Qt::gray);
ui->graphicsView->setScene(scene);
item->setZValue(0);
ui->graphicsView->fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
ui->graphicsView->show();===
I want to access layers , Path objects created in SVG. So i can change color, select the object with mouse. hide ON/OFF of layers and objects in the file.Please someone can guide me.
Thanks,
-
this may be the example you want to have a peek at
https://doc.qt.io/qt-5/qtwidgets-graphicsview-elasticnodes-example.html -
@Ra_J You cannot manipulate individual SVG elements in QGraphicsSvgItem. However, you can call
setElementId()and only display a sub-element in the Item. Create multiple QGraphicsSvgItems and set a different element ID for each.See the example code at https://doc.qt.io/qt-5/qgraphicssvgitem.html
You can then:
- Call QGraphicsItem::setVisible() to show/hide an item.
- Apply QGraphicsColorizeEffect to change the colour of an item.
To make this work, you probably need to re-organize your SVG file a bit.
-
@Ra_J You cannot manipulate individual SVG elements in QGraphicsSvgItem. However, you can call
setElementId()and only display a sub-element in the Item. Create multiple QGraphicsSvgItems and set a different element ID for each.See the example code at https://doc.qt.io/qt-5/qgraphicssvgitem.html
You can then:
- Call QGraphicsItem::setVisible() to show/hide an item.
- Apply QGraphicsColorizeEffect to change the colour of an item.
To make this work, you probably need to re-organize your SVG file a bit.