Click here to Skip to main content
11,477,007 members (73,299 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Windows Linux QT
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
Posted 30-Jul-12 13:16pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try to use following way:

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();
....
}

Alternatively, you can also look links:
http://www.archivum.info/qt4-preview-feedback@trolltech.com/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[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 274
1 Richard Deeming 245
2 Andy Lanng 185
3 _duDE_ 175
4 Sascha Lefèvre 150
0 Sergey Alexandrovich Kryukov 7,675
1 OriginalGriff 7,246
2 Sascha Lefèvre 3,034
3 Maciej Los 2,491
4 Richard Deeming 2,305


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 31 Jul 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100