Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Regarding the Screen width and Height in Other Platforms

    General and Desktop
    2
    4
    870
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Pradeep Kumar
      Pradeep Kumar last edited by

      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 >>>>>>>>>>>>>>>>>> 703

      in landscape mode:

      landscape orientation >>>>>>>>>>>>>>>>>>>>
      landscape width >>>>>>>>>>>>>>>>>> 800
      landscape height >>>>>>>>>>>>>>>>>> 1172

      Here 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
      Qt,QML Developer

      jsulm 1 Reply Last reply Reply Quote 2
      • jsulm
        jsulm Lifetime Qt Champion @Pradeep Kumar last edited by

        @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."

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • Pradeep Kumar
          Pradeep Kumar last edited by

          @jsulm

          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
          Qt,QML Developer

          jsulm 1 Reply Last reply Reply Quote 2
          • jsulm
            jsulm Lifetime Qt Champion @Pradeep Kumar last edited by

            @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().

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • First post
              Last post