Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Get Display information using Qt

From Wiki
Jump to: navigation, search
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

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


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.

QtDisplayInfoSC1.jpg

Download Code Example

Related articles

This page was last modified on 11 October 2012, at 01:23.
74 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×