×
Namespaces

Variants
Actions
(Difference between revisions)

Change font in Qt application

From Nokia Developer Wiki
Jump to: navigation, search
fasttrack (Talk | contribs)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
 
(20 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{ReviewerApproved}}
+
[[Category:Qt]][[Category:UI]][[Category:Code Examples]][[Category:MeeGo Harmattan]][[Category:Symbian]][[Category:Qt C++ UI]]
{{ReviewerApproved}}
+
{{Abstract|This code example shows how to change font of a Qt (C++) application. This is done by setting the desired font {{Qapiname|QFont}} using {{Qapiname|QApplication::setFont()}}.}}
  
 
+
{{ArticleMetaData <!-- v1.2 -->
 
+
|sourcecode= [[Media:QtChangeFont.zip]]
 
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
+
|devices= Nokia 5800 XpressMusic
{{CodeSnippet
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|id=...
+
|platform= Symbian^1,Symbian^3, Meamo, MeeGo
|platform=S60 3rd Edition, FP1, FP2<br>S60 5th Edition
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|devices=Nokia 5800 XpressMusic
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|category=Qt for Symbian
+
|signing= Self-Signed
|subcategory=
+
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
|creationdate=June 12, 2009
+
|keywords= Font
|keywords=QApplication::setFont(), QApplication::font()
+
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20090612
 +
|author= [[User:Savaj]]
 
}}
 
}}
 
==Overview==
 
 
This code snippets shows how to change font of application in Qt. API '''QApplication::setFont()''' will set the font of application, and it take QFont as parameter. so normally we need to specify font using QFont API.
 
 
This snippet can be self-signed. As it does not use any API which require developer/certified signing.
 
 
==Preconditions==
 
 
* [http://pepper.troll.no/s60prereleases/ Download the latest Qt for S60 distribution from Qt].
 
* Install Qt for S60:[[Installing Qt on S60]]
 
* Check this link for installation guide: [http://pepper.troll.no/s60prereleases/doc/install-s60.html How to install the package].
 
* Go through this article: [[Getting started with Qt for S60]]
 
  
 
==Headers required==
 
==Headers required==
<code cpp>
+
<code cpp-qt>
 
#include <QFont>
 
#include <QFont>
 
</code>
 
</code>
Line 36: Line 32:
 
==Source==
 
==Source==
  
<code cpp>
+
<code cpp-qt>
//specify a new font.
+
//specify a new font.
QFont newFont("Courier", 8, QFont::Bold, true);
+
QFont newFont("Courier", 8, QFont::Bold, true);
//set font of application
+
//set font of application
QApplication::setFont(newFont);
+
QApplication::setFont(newFont);
 
</code>
 
</code>
 
  
 
==Postconditions==
 
==Postconditions==
  
The code snippet is expected to show font "Courier" on application.<br><br>
+
The code snippet is expected to show font "Courier" on application.
'''Font Courier (Bold and Italic)'''
+
<br><br>
+
[[Image:Font1.JPG]]
+
<br><br>
+
'''After changing font to Times'''
+
<br>
+
[[Image:Font2.JPG]]
+
  
 +
<gallery widths="300px" heights="400px">
 +
File:Font1.JPG|Font Courier (Bold and Italic)
 +
File:Font2.JPG|After changing font to Times
 +
</gallery>
  
==External links==
+
==Further links==
* QFont: [http://pepper.troll.no/s60prereleases/doc/qfont.html#details QFont reference]
+
* {{Qapiname|QFont}}
 
+
==Internal Links==
+
 
* [[How to use QFontComboBox]]
 
* [[How to use QFontComboBox]]
  
 
==Code Example==
 
==Code Example==
  
* The [[Media:QtChangeFont.zip|Code Example]] will show font Courier and you can change it to Times from menu. The example is tested on Nokia 5800 XpressMusic.
+
* [[File:QtChangeFont.zip]] shows how you can change text from font Courier to font Times from the menu. The example is tested on Nokia 5800 XpressMusic.
 
+
<!-- Translation --> [[pt:Archived:Como modificar a fonte de aplicações, em Qt]]
 
+
 
+
[[Category:Qt]][[Category:Qt for Symbian]][[Category:Code Examples]][[Category:UI]]
+

Latest revision as of 04:13, 11 October 2012

This code example shows how to change font of a Qt (C++) application. This is done by setting the desired font QFont using QApplication::setFont().

Article Metadata
Code ExampleTested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): Symbian^1,Symbian^3, Meamo, MeeGo
Symbian
Platform Security
Signing Required: Self-Signed
Article
Keywords: Font
Created: savaj (12 Jun 2009)
Last edited: hamishwillee (11 Oct 2012)

Contents

[edit] Headers required

#include <QFont>

[edit] Source

//specify a new font.
QFont newFont("Courier", 8, QFont::Bold, true);
//set font of application
QApplication::setFont(newFont);

[edit] Postconditions

The code snippet is expected to show font "Courier" on application.

[edit] Further links

[edit] Code Example

  • File:QtChangeFont.zip shows how you can change text from font Courier to font Times from the menu. The example is tested on Nokia 5800 XpressMusic.
This page was last modified on 11 October 2012, at 04:13.
527 page views in the last 30 days.
×