Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I find the screen/desktop size in Qt, so I can display a desktop notification?

Tags:

qt

I want to code a notification window at the bottom right corner of the desktop, so it works like Skype notifications when someone comes online. Can someone help me get the screen size of the desktop, so I can place my notification window at the bottom right corner using my Qt Application?

like image 493
Sanath Reddy Avatar asked Sep 24 '13 07:09

Sanath Reddy


2 Answers

You can use the QDesktopWidget

 QRect rec = QApplication::desktop()->screenGeometry();
 height = rec.height();
 width = rec.width();
like image 61
krammer Avatar answered Oct 16 '22 12:10

krammer


QScreen class (since Qt 5.0) provide information about size of screen (logical and physical), orientation and signals for changes.

QScreen *screen = QGuiApplication::primaryScreen();
QRect  screenGeometry = screen->geometry();
int height = screenGeometry.height();
int width = screenGeometry.width();

upd:

  • for multiscreen configuration please use QList <QScreen*> screens = QGuiApplication::screens();
  • for orientation (including multiscreen) please use screen->orientation() and (since Qt 5.2)screen->nativeOrientation()
like image 50
Andrey Azazello Yaromenok Avatar answered Oct 16 '22 11:10

Andrey Azazello Yaromenok