问题描述
如何使用QSettings保存和检索QFont?
我尝试了几种方法没有更好的输出
让我有任何想法可以将其保存在QSettings或任何其他方法中
How to save and retrieve QFont using QSettings?
I tried several method not any better output
give me any idea to save this in QSettings or in any other methods
推荐答案
void MyClass::writeSettings(QSettings &settings)
{
QFont font = this->font();
settings.setValue("reader.file.name", m_currentFile);
settings.setValue("reader.file.mimetype", m_currentMimeType);
settings.setValue("reader.file.position", textCursor().position());
settings.setValue("reader.font.family", font.family());
settings.setValue("reader.font.size", font.pointSize());
settings.setValue("reader.font.bold", font.bold());
settings.setValue("reader.font.italic", font.italic());
settings.setValue("reader.font", font().toString());
}
void MyClass::readSettings(QSettings &settings)
{
int filePosition = settings.value("reader.file.position", 0).toInt();
QString fontFamily = settings.value("reader.font.family", QString()).toString();
int fontSize = settings.value("reader.font.size", 12).toInt();
bool fontIsBold = settings.value("reader.font.bold", false).toBool();
bool fontIsItalic = settings.value("reader.font.italic", false).toBool();
....
}
另外,您也可以查看链接:
http: //www.archivum.info/[email protected]/2005-03/00084/Re-how-to-store-fonts-in-QSettings.html [ ^ ]
http://phrasis.googlecode.com/svn-history/r29/trunk/src/dialogimpl.cpp [ ^ ]
http://www.ahammer.ch/131 [ ^ ]
http://www.qtcentre.org/threads/48888-Save-application-settings [ ^ ]
Alternatively, you can also look links:
http://www.archivum.info/[email protected]/2005-03/00084/Re-how-to-store-fonts-in-QSettings.html[^]
http://phrasis.googlecode.com/svn-history/r29/trunk/src/dialogimpl.cpp[^]
http://www.ahammer.ch/131[^]
http://www.qtcentre.org/threads/48888-Save-application-settings[^]
这篇关于使用QSettings保存字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!