Namespaces
Variants
Actions
(Difference between revisions)

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

Jump to: navigation, search
m (Hamishwillee - Bot update - Merge KB into wiki)
Line 1: Line 1:
[[Category:Qt]][[Category:Code Examples]][[Category:UI]][[Category:Code Snippet]]
+
{{Archived|timestamp=20120613050125|user=[[User:Hamishwillee|<br />----]]|[[:Category:Qt Quick|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.}}
{{KBCS}}
+
[[Category:Qt C++ UI]][[Category:Code Snippet]][[Category:UI]][[Category:Code Snippet]]
{{ArticleMetaData
+
{{ArticleMetaData <!-- v1.2 -->
|id=CS001502
+
|platform=Qt
+
|devices=Nokia N97
+
|creationdate=20091124
+
|keywords=Qt, UI, style sheet
+
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
 
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|sdk=Qt 4.5 Garden Tech-preview
+
|devices= Nokia N97
|devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) -->
+
|sdk= Qt 4.5 Garden Tech-preview
|signing=<!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
+
|platform= Qt
|capabilities=<!-- Capabilities required (e.g. Location, NetworkServices.) -->
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|author=[[User:Taaidant]]
+
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. -->
 +
|keywords= Qt, UI, style sheet
 +
|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= 20091124
 +
|author= [[User:Taaidant]]
 +
<!-- The following are not in current metadata -->
 +
|id= CS001502
 
}}
 
}}
  
Line 22: Line 32:
 
==Preconditions==
 
==Preconditions==
  
* You know how to [[CS001503 - Using resources in Qt|use resources in your Qt application]].
+
* You know how to [[Using resources in Qt]].
  
 
== Applying a Qt style sheet to an application via QApplication ==
 
== Applying a Qt style sheet to an application via QApplication ==
Line 71: Line 81:
 
==See also==
 
==See also==
  
* [[CS001503 - Using resources in Qt]]
+
* [[Using resources in Qt]]
 
* [http://doc.trolltech.com/4.7/qfile.html QFile documentation]
 
* [http://doc.trolltech.com/4.7/qfile.html QFile documentation]
 
* [http://doc.trolltech.com/4.7/qtextstream.html QTextStream documentation]
 
* [http://doc.trolltech.com/4.7/qtextstream.html QTextStream documentation]
Line 77: 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]
* [[CS001501 - 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]] [[Category:Symbian]]

Revision as of 08:01, 13 June 2012

Archived.png
Archived: 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

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

535 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved