There is a little svg file named t.svg below:
-sharpifndef SVG_WIDGET_H
-sharpdefine SVG_WIDGET_H
-sharpinclude <QWidget>
-sharpinclude <QtSvg>
-sharpinclude <QVBoxLayout>
-sharpinclude <QPushButton>
-sharpinclude <QDomDocument>
class SVGWidget : public QWidget
{
Q_OBJECT
public:
SVGWidget(QWidget* parent = 0) : QWidget(parent)
{
m_btn = new QPushButton("Change");
connect(m_btn, SIGNAL(clicked(bool)), this, SLOT(change()));
QFile file(":/t.svg");
file.open(QFile::ReadOnly | QFile::Text);
m_domDoc.setContent(&file);
file.close();
m_svgWidget = new QSvgWidget;
m_svgWidget->load(m_domDoc.toByteArray());
QVBoxLayout* vLayout = new QVBoxLayout(this);
vLayout->addWidget(m_btn);
vLayout->addWidget(m_svgWidget);
this->setFixedSize(800, 480);
}
~SVGWidget()
{
}
public slots:
void change()
{
// change the value, I used two ways to try it, but both failed.
QDomNodeList domNodeList1 = m_domDoc.elementsByTagName("text");
// way 1
QDomText domText = domNodeList1.at(0).toText();
domText.setNodeValue("60");
qDebug() << "way 1" << domText.nodeValue();
// way 2
QDomNode domNode = domNodeList1.at(0);
domNode.setNodeValue("60");
qDebug() << "way 2" << domNode.nodeValue();
// repaint the widget
m_svgWidget->load(m_domDoc.toByteArray());
}
private:
QSvgWidget* m_svgWidget;
QPushButton* m_btn;
QDomDocument m_domDoc;
};
-sharpendif // SVG_WIDGET_H
Can someone give me some advice?
(it hasn"t been solved since the release of Qt forum and SF, so I"m sorry if I didn"t bother to translate and post it directly.)