×
Namespaces

Variants
Actions
(Difference between revisions)

Get screen coordinates in Qt

From Nokia Developer Wiki
Jump to: navigation, search
savaj (Talk | contribs)
(link updated)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
 
(16 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{CodeSnippet
+
[[Category:Qt]][[Category:UI]][[Category:Code Examples]]
|id=...
+
{{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()}}.}}
|platform=S60 3rd Edition, FP1, FP2<br>S60 5th Edition
+
 
|devices=Nokia 5800 XpressMusic
+
{{ArticleMetaData <!-- v1.2 -->
|category=Qt for S60
+
|sourcecode= [[Media:QtScreenCoordinates.zip]]
|subcategory=UI
+
|installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) -->
|creationdate=June 9, 2009
+
|devices= Nokia 5800 XpressMusic
|keywords=QDesktopWidget::availableGeometry(), QDesktopWidget::screenGeometry()
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
 +
|platform= S60 3rd Edition, FP1, FP2<br>S60 5th Edition
 +
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
 +
|dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 -->
 +
|signing= Self-Signed
 +
|capabilities= None
 +
|keywords= QDesktopWidget::availableGeometry(), QDesktopWidget::screenGeometry()
 +
|language= <!-- Language category code for non-English topics - e.g. Lang-Chinese -->
 +
|translated-by= <!-- [[User:XXXX]] -->
 +
|translated-from-title= <!-- Title only -->
 +
|translated-from-id= <!-- Id of translated revision -->
 +
|review-by= <!-- After re-review: [[User:username]] -->
 +
|review-timestamp= <!-- After re-review: YYYYMMDD -->
 +
|update-by= <!-- After significant update: [[User:username]]-->
 +
|update-timestamp= <!-- After significant update: YYYYMMDD -->
 +
|creationdate= 20090609
 +
|author= [[User:Savaj]]
 
}}
 
}}
 
==Overview==
 
 
This code snippets shows how to get screen coordinates/screen size  in 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().
 
 
This snippet can be self-signed. As it does not use any API which require developer/symbian signed certificate.
 
 
==Preconditions==
 
 
* [http://pepper.troll.no/s60prereleases/ Download the latest Qt for S60 distribution from Qt Software].
 
* 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].
 
* Go through this article: [[Getting started with Qt for S60]]
 
  
 
==Source==
 
==Source==
  
<code cpp>
+
<code cpp-qt>
 
QDesktopWidget* desktopWidget = QApplication::desktop();
 
QDesktopWidget* desktopWidget = QApplication::desktop();
 
//get client rect.
 
//get client rect.
Line 39: Line 42:
  
 
'''Screen Coordinates for 640x360'''<br><br>
 
'''Screen Coordinates for 640x360'''<br><br>
[[Image:ScreenCoordinates2.JPG]]
+
[[File:ScreenCoordinates2.JPG]]
  
 
'''Screen Coordinates for 360x640'''<br><br>
 
'''Screen Coordinates for 360x640'''<br><br>
[[Image:ScreenCoordinates1.JPG]]
+
[[File:ScreenCoordinates1.JPG]]
  
 
==Code Example==
 
==Code Example==
  
* The [[Media:QtScreenCoordinates.zip|Code Example]] 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:MeeGo Harmattan]] [[Category:Symbian]]
<br>
+
<!-- Translation --> [[zh-hans:在Qt中获取屏幕坐标]]
 
+
 
+
[[Category:Qt]][[Category:Qt for S60]][[Category:Code Examples]][[Category:UI]]
+

Latest revision as of 04:16, 11 October 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 (11 Oct 2012)

[edit] Source

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


[edit] Postconditions

You will get application rect.

Screen Coordinates for 640x360

ScreenCoordinates2.JPG

Screen Coordinates for 360x640

ScreenCoordinates1.JPG

[edit] Code Example

This page was last modified on 11 October 2012, at 04:16.
168 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.

×