Get screen coordinates in Qt
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 Example
Source file: Media:QtScreenCoordinates.zip
Tested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition
S60 5th Edition
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)
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
Screen Coordinates for 360x640
Code Example
- File:QtScreenCoordinates.zip shows screen coordinates on screen and example is tested on Nokia 5800 XpressMusic.


Didn't work properly with Qt 4.7.3 and N8. First time availableGeometry was ok, but after screen orientation change it doesn't give full screen coordinates anymore but QRect(0,92 360x487).
If this is a problem with the generic API can you please raise a qt defect: https://bugreports.qt-project.org/secure/Dashboard.jspa , pointing them to this example.
--hamishwillee 06:02, 3 June 2011 (EEST)