×
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 (Text replace - "<code cpp>" to "<code cpp-qt>")
 
(5 intermediate revisions by one user not shown)
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.2 -->
{{ArticleMetaData <!-- v1.1 -->
+
|sourcecode= [[Media:QtScreenCoordinates.zip]]
|sourcecode= [[Media:QtScreenCoordinates.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]]) -->
 
|devices= Nokia 5800 XpressMusic
 
|devices= Nokia 5800 XpressMusic
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==
  
<code cpp>
+
<code cpp-qt>
 
QDesktopWidget* desktopWidget = QApplication::desktop();
 
QDesktopWidget* desktopWidget = QApplication::desktop();
 
//get client rect.
 
//get client rect.
Line 56: 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.
123 page views in the last 30 days.
×