Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Regarding the Screen width and Height in Other Platforms

Regarding the Screen width and Height in Other Platforms

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.1k Views 1 Watching
  • 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 KumarP Offline
    Pradeep KumarP Offline
    Pradeep Kumar
    wrote on last edited by
    #1

    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

    jsulmJ 1 Reply Last reply
    2
    • Pradeep KumarP Pradeep Kumar

      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,

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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
      0
      • Pradeep KumarP Offline
        Pradeep KumarP Offline
        Pradeep Kumar
        wrote on last edited by
        #3

        @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

        jsulmJ 1 Reply Last reply
        2
        • Pradeep KumarP Pradeep Kumar

          @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,

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved