Namespaces
Variants
Actions
(Difference between revisions)

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

Jump to: navigation, search
m (Hamishwillee - Bot change of template (Template:CodeSnippet) - now using Template:ArticleMetaData)
m (Hamishwillee - Remove "standard" preconditions)
Line 1: Line 1:
 +
[[Category:Qt]][[Category:Code Examples]][[Category:UI]][[Category:Code Snippet]]
 
{{KBCS}}
 
{{KBCS}}
 
{{ArticleMetaData
 
{{ArticleMetaData
Line 4: Line 5:
 
|platform=Qt
 
|platform=Qt
 
|devices=Nokia N97
 
|devices=Nokia N97
|category=Qt
+
|creationdate=20091124
|subcategory=UI
+
|creationdate=November 24, 2009
+
 
|keywords=Qt, UI, style sheet
 
|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=<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
+
|sdk=Qt 4.5 Garden Tech-preview
 
|devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 
|devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 
|signing=<!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 
|signing=<!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
Line 23: Line 21:
  
 
==Preconditions==
 
==Preconditions==
 
* Qt is installed on your platform.
 
** 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]].
 
* You know how to [[CS001503 - Using resources in Qt|use resources in your Qt application]].
Line 88: Line 78:
 
* [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]]
 
* [[CS001501 - Creating a gradient background for a QPushButton with style sheet]]
 
[[Category:Qt]][[Category:Code Examples]][[Category: UI]][[Category:Code Snippet]]
 

Revision as of 07:04, 27 October 2011

Template:KBCS

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 (27 Oct 2011)

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

488 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