Archived:Applying a Qt style sheet to an application via QApplication
hamishwillee
(Talk | contribs) m (Bot change of links to internal format.) |
hamishwillee
(Talk | contribs) m (Text replace - "<code cpp>" to "<code cpp-qt>") |
||
| (8 intermediate revisions by one user not shown) | |||
| Line 1: | Line 1: | ||
| − | {{ | + | {{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.}} |
| − | {{ | + | [[Category:Qt C++ UI]][[Category:Code Snippet]][[Category:UI]][[Category:Code Snippet]] |
| − | | | + | {{ArticleMetaData <!-- v1.2 --> |
| − | | | + | |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]]) --> |
| − | | | + | |devices= Nokia N97 |
| − | | | + | |sdk= Qt 4.5 Garden Tech-preview |
| − | | | + | |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== | ||
| − | + | * You know how to [[Using resources in Qt]]. | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | * You know how to [[ | + | |
== 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 69: | Line 77: | ||
===Postconditions=== | ===Postconditions=== | ||
| − | Now you can style your application with [http://doc.trolltech.com/stylesheet.html Qt style sheets]. | + | Now you can style your application with [http://doc.trolltech.com/4.7/stylesheet.html Qt style sheets]. |
==See also== | ==See also== | ||
| − | * [[ | + | * [[Using resources in Qt]] |
| − | * [http://doc.trolltech.com/qfile.html QFile documentation] | + | * [http://doc.trolltech.com/4.7/qfile.html QFile documentation] |
| − | * [http://doc.trolltech.com/qtextstream.html QTextStream documentation] | + | * [http://doc.trolltech.com/4.7/qtextstream.html QTextStream documentation] |
| − | * [http://doc.trolltech.com/qapplication.html QApplication documentation] | + | * [http://doc.trolltech.com/4.7/qapplication.html QApplication documentation] |
| − | * [http://doc.trolltech.com/qapplication.html#qApp qApp macro] | + | * [http://doc.trolltech.com/4.7/qapplication.html#qApp qApp macro] |
| − | * [http://doc.trolltech.com/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 Harmattan]] [[Category:Symbian]] |
| − | + | ||
| − | + | ||
Latest revision as of 04:13, 11 October 2012
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.
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
(11 Oct 2012)
Contents |
Overview
This example shows you how to apply a style sheet application-wide.
Preconditions
- You know how to Using resources in Qt.
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.

