Qt之SVG:Qt简单使用SVG的介绍_qt svg-CSDN博客
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
<circle cx="100" cy="50" r="40" stroke="black"
stroke-width="2" fill="green" />
</svg>
svg标签中包含了一个circle标签,circle元素的属性定义了这个圆的特性。
圆心:(100,50),半径:40
----------------------------------
1.
QGraphicsSvgItem:可用于呈现SVG文件内容的QGraphicsItem
QString path = QApplication::applicationDirPath() + "/circle.svg";
qDebug() << "[" << __FILE__ << __LINE__ << "]" << path;
QGraphicsSvgItem * item = new QGraphicsSvgItem(path);
item->setFlag(QGraphicsItem::ItemIsMovable);
QGraphicsScene scene;
scene.addItem(item);
QGraphicsView view;
view.setScene(&scene);
view.show();
2.
QString path = QApplication::applicationDirPath() + "/circle.svg";
qDebug() << "[" << __FILE__ << __LINE__ << "]" << path;
QSvgWidget w(path);
w.resize(300,300);
w.show();
3.
QString path = QApplication::applicationDirPath() + "/circle.svg";
qDebug() << "[" << __FILE__ << __LINE__ << "]" << path;
QSvgRenderer render;
render.load(path);
QSize size = render.defaultSize();
qDebug() << "[" << __FILE__ << __LINE__ << "]" << size;
//(82,82): 40 + 40 + 2
QPixmap pix(size * 5);
qDebug() << "[" << __FILE__ << __LINE__ << "]" <<pix.size();
//pix.fill(Qt::transparent);
pix.fill(Qt::red);
QPainter painter(&pix);
painter.setRenderHint(QPainter::Antialiasing);
render.render(&painter);
QLabel label;
label.setPixmap(pix);
label.setAlignment(Qt::AlignTop);
label.show();