读取画笔颜色失败,请问是什么原因呢?
bool GraphicsItem::readBaseAttributes(QXmlStreamReader *xml)
{ qreal x = xml->attributes().value(tr("x")).toDouble();
qreal y = xml->attributes().value(tr("y")).toDouble();
m_width = xml->attributes().value("width").toDouble();
m_height = xml->attributes().value("height").toDouble();
pencolor_r=xml->attributes().value("pencolor.r").toInt();
pencolor_g=xml->attributes().value("pencolor.g").toInt();
pencolor_b=xml->attributes().value("pencolor.b").toInt();
}
bool GraphicsItem::writeBaseAttributes(QXmlStreamWriter *xml)
{ xml->writeAttribute(tr("rotate"),QString("%1").arg(rotation()));
xml->writeAttribute(tr("x"),QString("%1").arg(pos().x()));
xml->writeAttribute(tr("y"),QString("%1").arg(pos().y()));
xml->writeAttribute(tr("z"),QString("%1").arg(zValue()));
xml->writeAttribute(tr("width"),QString("%1").arg(m_width));
xml->writeAttribute(tr("height"),QString("%1").arg(m_height));
xml->writeAttribute(tr("pencolor.r"),QString("%1").arg(m_pen.color().red()));
xml->writeAttribute(tr("pencolor.g"),QString("%1").arg(m_pen.color().green()));
xml->writeAttribute(tr("pencolor.b"),QString("%1").arg(m_pen.color().blue()));
return true;
}
这个是在.h文件中变量的定义:
int getpenClor()
{ pencolor_r=m_pen.color().red();
pencolor_g=m_pen.color().green();
pencolor_b=m_pen.color().blue();}
int pencolor_r;
int pencolor_g;
int pencolor_b;
}