×
Namespaces

Variants
Actions
(Difference between revisions)

Get Display information using Qt

From Nokia Developer Wiki
Jump to: navigation, search
somnathbanik (Talk | contribs)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
[[Category:Qt Mobility]]
 
[[Category:Qt Mobility]]
{{CodeSnippet
+
{{ArticleMetaData
 
|id=...
 
|id=...
 
|platform=S60 3rd Edition, FP1, FP2<br>S60 5th Edition
 
|platform=S60 3rd Edition, FP1, FP2<br>S60 5th Edition
Line 8: Line 8:
 
|creationdate=March 30, 2010
 
|creationdate=March 30, 2010
 
|keywords= QSystemDisplayInfo, QListWidget, QScrollArea
 
|keywords= QSystemDisplayInfo, QListWidget, QScrollArea
 +
 +
|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]]) -->
 +
|sdk=<!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
 +
|devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 +
|signing=<!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
 +
|capabilities=<!-- Capabilities required (e.g. Location, NetworkServices.) -->
 +
|author=[[User:Yashu]]
 
}}
 
}}
  
Line 23: Line 31:
  
 
==Headers required==
 
==Headers required==
<code cpp>
+
<code cpp-qt>
 
#include <qsysteminfo.h>
 
#include <qsysteminfo.h>
 
</code>
 
</code>
  
 
== .pro file==
 
== .pro file==
Modify your .pro file as follows.
+
Modify your '''.pro''' file as follows.
  
<code cpp>
+
<code cpp-qt>
 
QT += core \
 
QT += core \
 
     gui \
 
     gui \
Line 45: Line 53:
 
==Header file==
 
==Header file==
  
<code cpp>
+
<code cpp-qt>
 
/* GetDisplayInfo.h */
 
/* GetDisplayInfo.h */
  
Line 83: Line 91:
 
==Source file==
 
==Source file==
  
<code cpp>
+
<code cpp-qt>
 
/* GetDisplayInfo.cpp */
 
/* GetDisplayInfo.cpp */
  
Line 165: Line 173:
 
* [[Get System information using Qt for Symbian]]
 
* [[Get System information using Qt for Symbian]]
  
[[Category:Code Examples]]
+
[[Category:Code Examples]][[Category:MeeGo Harmattan]] [[Category:Symbian]]

Latest revision as of 04:23, 11 October 2012

Article Metadata
Tested with
Devices(s): Nokia 5800 and Nokia N97.
Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition
Symbian
Article
Keywords: QSystemDisplayInfo, QListWidget, QScrollArea
Created: Yashu (30 Mar 2010)
Last edited: hamishwillee (11 Oct 2012)

Contents

[edit] Overview

This code example shows how to access display information from the system. For example to get color depth and display brightness of the device. Code example use QSystemDisplayInfo API from QtMobility APIs.

This snippet requires ReadDeviceData capabilities. Self-signing is not possible, a Developer certificate is needed to sign application for testing for individual phones use the Symbian Open Online Signing website.

[edit] Prerequisite


[edit] Headers required

#include <qsysteminfo.h>

[edit] .pro file

Modify your .pro file as follows.

QT += core \
gui \
network
INCLUDEPATH += d:/qtmobility/src/systeminfo
INCLUDEPATH += D:/QtMobility/src/global
 
CONFIG += mobility
MOBILITY = systeminfo
symbian:TARGET.CAPABILITY = ReadDeviceData


[edit] Header file

/* GetDisplayInfo.h */
 
#ifndef GETDISPLAYINFO_H
#define GETDISPLAYINFO_H
 
#include <QtGui/QMainWindow>
#include <qsysteminfo.h>
 
QTM_USE_NAMESPACE;
 
class QListWidget;
class QScrollArea;
 
class GetDisplayInfo : public QMainWindow
{
Q_OBJECT
 
public:
GetDisplayInfo(QWidget *parent = 0);
~GetDisplayInfo();
 
private:
void setWidgetGeometry(QSize* screenSize);
void getDisplayInformation();
 
private:
QSystemDisplayInfo* sysInfo;
QListWidget *listWidget;
QScrollArea *scrollArea;
};
 
#endif // GETDISPLAYINFO_H

[edit] Source file

/* GetDisplayInfo.cpp */
 
#include "GetDisplayInfo.h"
#include <QListWidget>
#include <QScrollArea>
 
GetDisplayInfo::GetDisplayInfo(QWidget *parent)
: QMainWindow(parent)
{
setWindowTitle("Get display information");
 
/*The sysInfo becomes a child of the GetDisplayInfo, and will be destroyed when the GetDisplayInfo is deleted */
sysInfo = new QSystemDisplayInfo(this);
 
/* To show items in list view */
listWidget = new QListWidget();
listWidget->setObjectName(QString::fromUtf8("listWidget"));
 
/* To make UI scrollable */
scrollArea = new QScrollArea();
setWidgetGeometry(&(size()));
 
/* scrollArea takes ownership of the listWidget, so no need to delete it */
scrollArea->setWidget(listWidget);
scrollArea->setAlignment(Qt::AlignLeft);
scrollArea->setWidgetResizable(true);
 
/* QMainWindow takes ownership of the scrollArea, so no need to delete it */
setCentralWidget(scrollArea);
getDisplayInformation();
 
}
 
GetDisplayInfo::~GetDisplayInfo()
{
}
 
void GetDisplayInfo::setWidgetGeometry(QSize* screenSize)
{
resize(*screenSize);
QRect rect(0,0,screenSize->width(), screenSize->height());
listWidget->setGeometry(rect);
}
 
void GetDisplayInfo::getDisplayInformation()
{
QString infoStr;
 
/* get color depth of screen */
infoStr.setNum(sysInfo->colorDepth(0));
infoStr.prepend("Color depth: ");
listWidget->addItem(infoStr);
 
/* get display brightness of screen */
infoStr.clear();
infoStr.setNum(sysInfo->displayBrightness(0));
infoStr.prepend("Display brightness: ");
listWidget->addItem(infoStr);
}


[edit] Postconditions

The code snippet is expected to read display information from device and show it on screen.

QtDisplayInfoSC1.jpg

[edit] Download Code Example

[edit] Related articles

This page was last modified on 11 October 2012, at 04:23.
90 page views in the last 30 days.
×