×
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 change of template (Template:CodeSnippet) - now using Template:ArticleMetaData)
hamishwillee (Talk | contribs)
m (Text replace - "<code cpp>" to "<code cpp-qt>")
 
(6 intermediate revisions by one user not shown)
Line 1: Line 1:
[[Category:Qt]][[Category:UI]]
+
[[Category:Qt]][[Category:UI]][[Category:Code Examples]]
{{ReviewerApproved|timestamp=20090923}}
+
{{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
+
{{ArticleMetaData <!-- v1.2 -->
|id=...
+
|sourcecode= [[Media:QtScreenCoordinates.zip]]
|platform=S60 3rd Edition, FP1, FP2<br>S60 5th Edition
+
|devices=Nokia 5800 XpressMusic
+
|category=Qt
+
|subcategory=UI
+
|creationdate=June 9, 2009
+
|keywords=QDesktopWidget::availableGeometry(), QDesktopWidget::screenGeometry()
+
 
+
|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]]) -->
 
|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]) -->
+
|devices= Nokia 5800 XpressMusic
|devicecompatability=<!-- Compatible devices (e.g.: All* (must have GPS) ) -->
+
|sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Nokia Qt SDK 1.1]) -->
|signing=<!-- Empty or one of Self-Signed, DevCert, Manufacturer -->
+
|platform= S60 3rd Edition, FP1, FP2<br>S60 5th Edition
|capabilities=<!-- Capabilities required (e.g. Location, NetworkServices. -->)
+
|devicecompatability= <!-- Compatible devices (e.g.: All* (must have GPS) ) -->
|author=[[User:Savaj]]
+
|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==
 
 
{{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==
  
<code cpp>
+
<code cpp-qt>
 
QDesktopWidget* desktopWidget = QApplication::desktop();
 
QDesktopWidget* desktopWidget = QApplication::desktop();
 
//get client rect.
 
//get client rect.
Line 47: 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==
  
* [[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:MeeGo Harmattan]] [[Category:Symbian]]
 
+
<!-- Translation --> [[zh-hans:在Qt中获取屏幕坐标]]
 
+
[[Category:Code Examples]]
+

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.
136 page views in the last 30 days.
×