×
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
copyeditor (Talk | contribs)
m (Protected "CS001502 - Applying a Qt style sheet to an application via QApplication" ([edit=sysop] (indefinite) [move=sysop] (indefinite)))
tanjaluodes (Talk | contribs)
m
Line 81: Line 81:
 
* [[CS001501 - Creating a gradient background for 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]][[Category:Code Snippet]]

Revision as of 14:00, 15 January 2010

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: tanjaluodes (15 Jan 2010)

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

168 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.

×