×
Namespaces

Variants
Actions
(Difference between revisions)

Archived:Applying a Qt style sheet to an application via QApplication

From Nokia Developer Wiki
Jump to: navigation, search
taaidant (Talk | contribs)
(Created page with '{{CodeSnippet |id= |platform=Qt |devices=N97 |category=Qt |subcategory=UI |creationdate=September 9, 2009 |keywords=Qt, UI, style sheet }} ==Overview== This example shows you h…')
 
copyeditor (Talk | contribs)
m
Line 1: Line 1:
 +
{{KBCS}}
 
{{CodeSnippet
 
{{CodeSnippet
|id=
+
|id=CS001502
 
|platform=Qt
 
|platform=Qt
|devices=N97
+
|devices=Nokia N97
 
|category=Qt
 
|category=Qt
 
|subcategory=UI
 
|subcategory=UI
|creationdate=September 9, 2009
+
|creationdate=November 24, 2009
 
|keywords=Qt, UI, style sheet
 
|keywords=Qt, UI, style sheet
 
}}
 
}}
Line 11: Line 12:
 
==Overview==
 
==Overview==
  
This example shows you how to apply a style sheet application wide.
+
This example shows you how to apply a style sheet application-wide.
  
 
==Preconditions==
 
==Preconditions==
  
* Qt is installed on your platform
+
* Qt is installed on your platform.
** S60
+
** S60:
 
*** Download Qt for S60 release from here: [http://pepper.troll.no/s60prereleases/ Qt for S60 pre-release]
 
*** Download Qt for S60 release from here: [http://pepper.troll.no/s60prereleases/ Qt for S60 pre-release]
 
*** Install Qt for S60: [[Installing Qt on S60]]
 
*** 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].
+
*** Check this link for installation guide: [http://pepper.troll.no/s60prereleases/doc/install-s60.html How to install the package]
** Maemo  
+
** Maemo:
 
*** More information about Qt on Maemo can be found here: [http://qt4.garage.maemo.org/ Qt4 Maemo port]
 
*** More information about Qt on Maemo can be found here: [http://qt4.garage.maemo.org/ Qt4 Maemo port]
  
* [http://wiki.forum.nokia.com/index.php/Tools:Using_resources_in_Qt You know how to use resources in you Qt application]
+
* You know how to [http://wiki.forum.nokia.com/index.php/CS001503_-_Using_resources_in_Qt use resources in your Qt application].
  
== Applying a Qt style sheet to application via QApplication ==
+
== Applying a Qt style sheet to an application via QApplication ==
  
 
<code cpp>
 
<code cpp>
Line 72: Line 73:
 
==See also==
 
==See also==
  
* [[Tools:Using resources in Qt]]
+
* [[CS001503 - Using resources in Qt]]
 
* [http://doc.trolltech.com/qfile.html QFile documentation]
 
* [http://doc.trolltech.com/qfile.html QFile documentation]
 
* [http://doc.trolltech.com/qtextstream.html QTextStream documentation]
 
* [http://doc.trolltech.com/qtextstream.html QTextStream documentation]
Line 78: Line 79:
 
* [http://doc.trolltech.com/qapplication.html#qApp qApp macro]
 
* [http://doc.trolltech.com/qapplication.html#qApp qApp macro]
 
* [http://doc.trolltech.com/stylesheet.html Qt style sheet documentation]
 
* [http://doc.trolltech.com/stylesheet.html Qt style sheet documentation]
* [[Tools:Creating a gradient background to a QPushButton with style sheet]]
+
* [[CS001501 - Creating a gradient background for a QPushButton with style sheet]]
  
 
[[Category:Qt]][[Category:Code Examples]][[Category: UI]]
 
[[Category:Qt]][[Category:Code Examples]][[Category: UI]]

Revision as of 16:35, 24 November 2009

Template:KBCS

Article Metadata
Tested with
Devices(s): Nokia N97
Compatibility
Platform(s): Qt
Symbian
Article
Keywords: Qt, UI, style sheet
Created: (24 Nov 2009)
Last edited: copyeditor (24 Nov 2009)

Contents

Overview

This example shows you how to apply a style sheet application-wide.

Preconditions

Applying a Qt style sheet to an application via QApplication

#include "yourwindow.h"
 
#include <QtGui>
#include <QApplication>
 
#include <QFile>
#include <QString>
#include <QTextStream>
 
void loadStyleSheet() {
/* Let's use QFile and point to a resource... */
QFile data(":/style.qss");
QString style;
/* ...to open the file */
if(data.open(QFile::ReadOnly)) {
/* QTextStream... */
QTextStream styleIn(&data);
/* ...read file to a string. */
style = styleIn.readAll();
data.close();
/* We'll use qApp macro to get the QApplication pointer
* and set the style sheet application wide. */

qApp->setStyleSheet(style);
}
}
 
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
YourWindow* w = new YourWindow();
/* Load style sheet */
loadStyleSheet();
w->showMaximized();
int returnValue = a.exec();
w->deleteLater();
return returnValue;
}

Postconditions

Now you can style your application with Qt style sheets.

See also

173 page views in the last 30 days.
×