Unsolved Regarding the Screen width and Height in Other Platforms
-
Hi,
I am using Android devices , to check the screen width and height in both Portrait and Landscape mode.
I am not getting the output as for portrait or landscape , its reversed, can u help me out where i have done mistake.
Output is :
in portrait mode :portrait orientation >>>>>>>>>>>>>>>>>>>>
portrait width >>>>>>>>>>>>>>>>>> 1280
portrait height >>>>>>>>>>>>>>>>>> 703in landscape mode:
landscape orientation >>>>>>>>>>>>>>>>>>>>
landscape width >>>>>>>>>>>>>>>>>> 800
landscape height >>>>>>>>>>>>>>>>>> 1172Here is the code:
In constructor :
QScreen *m_screen = qApp->primaryScreen(); connect(m_screen,SIGNAL(orientationChanged(Qt::ScreenOrientation)),this,SLOT(getScreenOrientation(Qt::ScreenOrientation))); m_screen->setOrientationUpdateMask(Qt::PortraitOrientation| Qt::LandscapeOrientation);
in the slot getScreenOrientation(Qt::ScreenOrientation)) :
qDebug () << "orientation :" << orientation << endl; switch (orientation) { case Qt::PortraitOrientation : portraitValue(); break; case Qt::LandscapeOrientation : landscapeValue(); break; default : qDebug () << " unknown >>>>>>>>>>>>>>>>>>>>" << endl; exit(0); }
and depending on the mode i am calling the respective functions:
in the portraitValue(); function :
QScreen *screen = qApp->primaryScreen(); int width = screen->availableSize().width(); int height = screen->availableSize().height(); qDebug () << " portrait orientation >>>>>>>>>>>>>>>>>>>>" << endl; qDebug () << "portrait width >>>>>>>>>>>>>>>>>>" << width << endl; qDebug () << "portrait height >>>>>>>>>>>>>>>>>>" << height << endl;
and in the landscapeValue(); function :
QScreen *screen1 = qApp->primaryScreen(); int width1 = screen1->availableSize().width(); int height1 = screen1->availableSize().height(); qDebug () << " landscape orientation >>>>>>>>>>>>>>>>>>>>" << endl; qDebug () << " landscape width >>>>>>>>>>>>>>>>>>" << width1 << endl; qDebug () << " landscape height >>>>>>>>>>>>>>>>>>" << height1 << endl;
Thanks,
-
@Pradeep-Kumar said in Regarding the Screen width and Height in Other Platforms:
QScreen
Shouldn't you use http://doc.qt.io/qt-5/qscreen.html#size-prop ?
availableSize() dpocumentation:
"This property holds the screen's available size in pixels.The available size is the size excluding window manager reserved areas such as task bars and system menus."
-
Thanks for the reply.
And as you can see when i am in Landscape mode , why the portraitValue() function is called
When the signal is emitted from the constructor.
Am i doing anything wrong in switch() statement
switch (orientation)
{
case Qt::PortraitOrientation :portraitValue(); break;
case Qt::LandscapeOrientation :
landscapeValue(); break;
default :
qDebug () << " unknown >>>>>>>>>>>>>>>>>>>>" << endl; exit(0);
}
Thanks,
-
@Pradeep-Kumar It is not the switch. I think you should use http://doc.qt.io/qt-5/qscreen.html#size-prop instead of availableSize().