Get Display information using Qt
hamishwillee
(Talk | contribs) m (Text replace - "Category:MeeGo" to "Category:MeeGo Harmattan") |
hamishwillee
(Talk | contribs) m (Text replace - "<code cpp>" to "<code cpp-qt>") |
||
| Line 31: | Line 31: | ||
==Headers required== | ==Headers required== | ||
| − | <code cpp> | + | <code cpp-qt> |
#include <qsysteminfo.h> | #include <qsysteminfo.h> | ||
</code> | </code> | ||
| Line 38: | Line 38: | ||
Modify your '''.pro''' file as follows. | Modify your '''.pro''' file as follows. | ||
| − | <code cpp> | + | <code cpp-qt> |
QT += core \ | QT += core \ | ||
gui \ | gui \ | ||
| Line 53: | Line 53: | ||
==Header file== | ==Header file== | ||
| − | <code cpp> | + | <code cpp-qt> |
/* GetDisplayInfo.h */ | /* GetDisplayInfo.h */ | ||
| Line 91: | Line 91: | ||
==Source file== | ==Source file== | ||
| − | <code cpp> | + | <code cpp-qt> |
/* GetDisplayInfo.cpp */ | /* GetDisplayInfo.cpp */ | ||
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
S60 5th Edition
Article
Keywords: QSystemDisplayInfo, QListWidget, QScrollArea
Created: Yashu
(30 Mar 2010)
Last edited: hamishwillee
(11 Oct 2012)
Contents |
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.
Prerequisite
- Install Qt for Symbian:Installing Qt on Symbian
- Install QtMobility APIs:Setting up environment for Qt Mobility API
Headers required
#include <qsysteminfo.h>.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
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
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);
}
Postconditions
The code snippet is expected to read display information from device and show it on screen.
Download Code Example
- Working Code Example is available to download from here.


