×
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
hamishwillee (Talk | contribs)
m (Bot fixing redirect link)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
 
(7 intermediate revisions by one user not shown)
Line 1: Line 1:
{{KBCS}}
+
{{Archived|timestamp=20120613050125|user=[[User:Hamishwillee|&lt;br /&gt;----]]|[[: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.}}
{{CodeSnippet
+
[[Category:Qt C++ UI]][[Category:Code Snippet]][[Category:UI]][[Category:Code Snippet]]
|id=CS001502
+
{{ArticleMetaData <!-- v1.2 -->
|platform=Qt
+
|sourcecode= <!-- Link to example source code (e.g. [[Media:The Code Example ZIP.zip]]) -->
|devices=Nokia N97
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|category=Qt
+
|devices= Nokia N97
|subcategory=UI
+
|sdk= Qt 4.5 Garden Tech-preview
|creationdate=November 24, 2009
+
|platform= Qt
|keywords=Qt, UI, style sheet
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 +
|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 16: Line 32:
 
==Preconditions==
 
==Preconditions==
  
* Qt is installed on your platform.
+
* You know how to [[Using resources in Qt]].
** S60:
+
*** 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]]
+
*** Check this link for installation guide: [http://pepper.troll.no/s60prereleases/doc/install-s60.html How to install the package]
+
** Maemo:
+
*** More information about Qt on Maemo can be found here: [http://qt4.garage.maemo.org/ Qt4 Maemo port]
+
 
+
* You know how to [[CS001503 - Using resources in Qt|use resources in your Qt application]].
+
  
 
== Applying a Qt style sheet to an application via QApplication ==
 
== Applying a Qt style sheet to an application via QApplication ==
  
<code cpp>
+
<code cpp-qt>
 
#include "yourwindow.h"
 
#include "yourwindow.h"
  
Line 73: 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 79: 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]]
+
* [[Archived:Creating a gradient background for a QPushButton with style sheet]][[Category:MeeGo Harmattan]] [[Category:Symbian]]
 
+
[[Category:Qt]][[Category:Code Examples]][[Category: UI]][[Category:Code Snippet]]
+

Latest revision as of 04:13, 11 October 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
Compatibility
Platform(s): Qt
Symbian
Article
Keywords: Qt, UI, style sheet
Created: taaidant (24 Nov 2009)
Last edited: hamishwillee (11 Oct 2012)

Contents

[edit] Overview

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

[edit] Preconditions

[edit] 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;
}

[edit] Postconditions

Now you can style your application with Qt style sheets.

[edit] See also

This page was last modified on 11 October 2012, at 04:13.
186 page views in the last 30 days.