如何打开像png文件一样的svg文件。 例如它适用于 png 文件:
scene=new QGraphicsScene(QRect(10, 10, 680, 520));
view=new QGraphicsView(this);
image=new QGraphicsPixmapItem(QPixmap("example.png"));
scene ->addItem(image);
view ->setScene(scene);
view ->setGeometry(QRect(270, 35, 700, 540));
有什么想法吗?
最佳答案
根据我的评论,您可以按照 documentation 使用 QGraphicsSvgItem :
QGraphicsSvgItem::QGraphicsSvgItem(const QString & fileName, QGraphicsItem * parent = 0)
Constructs a new item with the given parent and loads the contents of the SVG file with the specified fileName.
所以,你基本上会写如下内容:
QGraphicsSvgItem *item = new QGraphicsSvgItem("example.svg");
如果您希望将它与 QSvgRenderer
一起使用,您也可以按照文档中的示例进行操作。
QSvgRenderer *renderer = new QSvgRenderer(QStringLiteral("example.svg"));
QGraphicsSvgItem *item = new QGraphicsSvgItem();
item->setSharedRenderer(renderer);
item->setElementId(QStringLiteral("example"));
在这里你甚至可以找到一个更复杂的例子:
关于c++ - 如何在QT中打开svg文件(QGraphicsView),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21099276/