×
Namespaces

Variants
Actions
Revision as of 13:59, 13 June 2012 by hamishwillee (Talk | contribs)

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

From Nokia Developer Wiki
Jump to: navigation, search

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
Compatibility
Platform(s): Qt
Symbian
Article
Keywords: Qt, UI, style sheet
Created: taaidant (24 Nov 2009)
Last edited: hamishwillee (13 Jun 2012)

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

190 page views in the last 30 days.