×
Namespaces

Variants
Actions
(Difference between revisions)

Get screen coordinates in Qt

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Bot update - Fix ArticleMetaData and RevieweApproval)
hamishwillee (Talk | contribs)
m (Hamishwillee - Tidy wiki text)
Line 1: Line 1:
[[Category:Qt]][[Category:UI]]
+
[[Category:Qt]][[Category:UI]][[Category:Code Examples]]
 
+
{{Abstract|This code example shows how to get screen coordinates and screen size in a Qt application. The API [http://doc.qt.nokia.com/stable/qdesktopwidget.html QDesktopWidget::screenGeometry()] returns the application rect (screen size of device) and API {{Icode|QDesktopWidget::availableGeometry()}} returns client rect (screen size minus status pane).  It is useful in UI applications that do not use layout managers by implementing virtual {{Icode|QWidget::resizeEvent()}}.}}
  
 
{{ArticleMetaData <!-- v1.1 -->
 
{{ArticleMetaData <!-- v1.1 -->
Line 10: Line 10:
 
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
|signing= <!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
+
|signing= Self-Signed
|capabilities= <!-- Capabilities required (e.g. Location, NetworkServices. -->)
+
|capabilities= None
 
|keywords= QDesktopWidget::availableGeometry(), QDesktopWidget::screenGeometry()
 
|keywords= QDesktopWidget::availableGeometry(), QDesktopWidget::screenGeometry()
|id= ...
 
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 
|translated-by= <!-- [[User:XXXX]] -->
 
|translated-by= <!-- [[User:XXXX]] -->
Line 24: Line 23:
 
|creationdate= 20090609
 
|creationdate= 20090609
 
|author= [[User:Savaj]]
 
|author= [[User:Savaj]]
<!-- The following are not in current metadata -->
 
|subcategory= UI
 
|category= Qt
 
 
}}
 
}}
 
==Overview==
 
 
{{Abstract|visible=true|This code example shows how to get screen coordinates and screen size in a Qt application. The API [http://doc.qt.nokia.com/stable/qdesktopwidget.html QDesktopWidget::screenGeometry()] returns the application rect (screen size of device) and API {{Icode|QDesktopWidget::availableGeometry()}} returns client rect (screen size minus status pane).  It is useful in UI applications that do not use layout managers by implementing virtual {{Icode|QWidget::resizeEvent()}}.}}
 
 
This snippet can be self-signed.
 
 
==Preconditions==
 
 
* Download and install the [[Qt SDK]].
 
  
 
==Source==
 
==Source==
Line 64: Line 50:
  
 
* [[File:QtScreenCoordinates.zip]] shows screen coordinates on screen and example is tested on Nokia 5800 XpressMusic.
 
* [[File:QtScreenCoordinates.zip]] shows screen coordinates on screen and example is tested on Nokia 5800 XpressMusic.
 
 
[[Category:Code Examples]]
 

Revision as of 07:47, 10 February 2012

This code example shows how to get screen coordinates and screen size in a Qt application. The API QDesktopWidget::screenGeometry() returns the application rect (screen size of device) and API QDesktopWidget::availableGeometry() returns client rect (screen size minus status pane). It is useful in UI applications that do not use layout managers by implementing virtual QWidget::resizeEvent().

Article Metadata
Code ExampleTested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition
Symbian
Platform Security
Signing Required: Self-Signed
Capabilities: None
Article
Keywords: QDesktopWidget::availableGeometry(), QDesktopWidget::screenGeometry()
Created: savaj (09 Jun 2009)
Last edited: hamishwillee (10 Feb 2012)

Source

QDesktopWidget* desktopWidget = QApplication::desktop();
//get client rect.
QRect clientRect = desktopWidget->availableGeometry();
 
//get application rect.
QRect applicationRect = desktopWidget->screenGeometry();


Postconditions

You will get application rect.

Screen Coordinates for 640x360

ScreenCoordinates2.JPG

Screen Coordinates for 360x640

ScreenCoordinates1.JPG

Code Example

140 page views in the last 30 days.