(Difference between revisions)

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

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
hamishwillee (Talk | contribs)
m (Text replace - "Category:MeeGo" to "Category:MeeGo Harmattan")
Line 87: Line 87:
* [http://doc.trolltech.com/4.7/qapplication.html#qApp qApp macro]
* [http://doc.trolltech.com/4.7/qapplication.html#qApp qApp macro]
* [http://doc.trolltech.com/4.7/stylesheet.html Qt style sheet documentation]
* [http://doc.trolltech.com/4.7/stylesheet.html Qt style sheet documentation]
* [[Archived:Creating a gradient background for a QPushButton with style sheet]][[Category:MeeGo]] [[Category:Symbian]]
* [[Archived:Creating a gradient background for a QPushButton with style sheet]][[Category:MeeGo Harmattan]] [[Category:Symbian]]

Revision as of 13:59, 13 June 2012

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Qt Quick should be used for all UI development on mobile devices. The approach described in this article (using C++ for the Qt app UI) is deprecated.

Article Metadata
Tested with
SDK: Qt 4.5 Garden Tech-preview
Devices(s): Nokia N97
Platform(s): Qt
Keywords: Qt, UI, style sheet
Created: taaidant (24 Nov 2009)
Last edited: hamishwillee (13 Jun 2012)



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


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();
/* We'll use qApp macro to get the QApplication pointer
* and set the style sheet application wide. */

int main(int argc, char *argv[]) {
QApplication a(argc, argv);
YourWindow* w = new YourWindow();
/* Load style sheet */
int returnValue = a.exec();
return returnValue;


Now you can style your application with Qt style sheets.

See also

158 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.