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. Not able to get screen resolution with QDesktopWidget.

Not able to get screen resolution with QDesktopWidget.

Scheduled Pinned Locked Moved Unsolved General and Desktop
qdesktopwidgetresolution
7 Posts 3 Posters 6.2k 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.
  • AhtiA Offline
    AhtiA Offline
    Ahti
    wrote on last edited by Ahti
    #1

    Why doesn't the following code display the screen resolution :

      QMessageBox* EyeCare::constructMessageBox(QWidget *parent,QMessageBox *message,
                                      int x,int y,int w,int h,
                                      QString style){
        message = new QMessageBox(parent) ;
        message->setGeometry(x,y,w,h);
        message->setStyleSheet(style);
        return message ;
    }
    
    void EyeCare::setupSimpleAndErrorMessage(){
    
        showSimpleMessage = constructMessageBox(this,showSimpleMessage,400,400,0,0
                                                ,"color:#D3D3D3;background-color:rgb(32,52,60);"
                                                 "font: 75 bold 12pt Arial;") ;
    }
    
        QDesktopWidget widget ;
        setupSimpleAndErrorMessage() ;
        QRect screenSize = widget.availableGeometry(widget.primaryScreen());
        showSimpleMessage->setText("Height: " + screenSize.height()  );
        showSimpleMessage->show();
    

    Instead of displaying the height. It displays the current location of my qt project.
    what is wrong with it ??
    please help...

    what is a signature ?? Lol

    1 Reply Last reply
    0
    • hskoglundH Offline
      hskoglundH Offline
      hskoglund
      wrote on last edited by
      #2

      Hi, try this:

      QDesktopWidget* widget = qApp->desktop();
      setupSimpleAndErrorMessage() ;
      QRect screenSize = widget->availableGeometry(widget->primaryScreen());
      showSimpleMessage->setText("Height: " + screenSize.height()  );
      showSimpleMessage->show();
      
      AhtiA 1 Reply Last reply
      2
      • hskoglundH hskoglund

        Hi, try this:

        QDesktopWidget* widget = qApp->desktop();
        setupSimpleAndErrorMessage() ;
        QRect screenSize = widget->availableGeometry(widget->primaryScreen());
        showSimpleMessage->setText("Height: " + screenSize.height()  );
        showSimpleMessage->show();
        
        AhtiA Offline
        AhtiA Offline
        Ahti
        wrote on last edited by
        #3

        @hskoglund Still displaying the location of my qt project. :(

        what is a signature ?? Lol

        hskoglundH 1 Reply Last reply
        0
        • AhtiA Ahti

          @hskoglund Still displaying the location of my qt project. :(

          hskoglundH Offline
          hskoglundH Offline
          hskoglund
          wrote on last edited by
          #4

          Hmm, I tested the code like this: created a new empty Widgets app, then modified mainwindow.cpp so it looks like this:

          #include "mainwindow.h"
          #include "ui_mainwindow.h"
          #include "QDesktopWidget"  // <-- added
          #include "qdebug.h"        // <-- added
          
          MainWindow::MainWindow(QWidget *parent) :
              QMainWindow(parent),
              ui(new Ui::MainWindow)
          {
              ui->setupUi(this);
          
          // added these 3 lines:
              QDesktopWidget* widget = qApp->desktop();
              QRect screenSize = widget->availableGeometry(widget->primaryScreen());
              qDebug() << "Height: " << screenSize.height();
          }
          
          MainWindow::~MainWindow()
          {
              delete ui;
          }
          

          Debug output shows height of my desktop (minus 30 because of Windows 7's taskbar)

          AhtiA 1 Reply Last reply
          2
          • hskoglundH hskoglund

            Hmm, I tested the code like this: created a new empty Widgets app, then modified mainwindow.cpp so it looks like this:

            #include "mainwindow.h"
            #include "ui_mainwindow.h"
            #include "QDesktopWidget"  // <-- added
            #include "qdebug.h"        // <-- added
            
            MainWindow::MainWindow(QWidget *parent) :
                QMainWindow(parent),
                ui(new Ui::MainWindow)
            {
                ui->setupUi(this);
            
            // added these 3 lines:
                QDesktopWidget* widget = qApp->desktop();
                QRect screenSize = widget->availableGeometry(widget->primaryScreen());
                qDebug() << "Height: " << screenSize.height();
            }
            
            MainWindow::~MainWindow()
            {
                delete ui;
            }
            

            Debug output shows height of my desktop (minus 30 because of Windows 7's taskbar)

            AhtiA Offline
            AhtiA Offline
            Ahti
            wrote on last edited by
            #5

            @hskoglund okay mine displays 1030 which means it subtracts 50 because of windows 10 taskbar. But why doesn't it display the same if use QMessageBox ? does your display it using QMessageBox ??

            what is a signature ?? Lol

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Did you update your code following @hskoglund suggestions ? If so, can you post the new version ?

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              AhtiA 1 Reply Last reply
              1
              • SGaistS SGaist

                Hi,

                Did you update your code following @hskoglund suggestions ? If so, can you post the new version ?

                AhtiA Offline
                AhtiA Offline
                Ahti
                wrote on last edited by
                #7

                @SGaist yes but i removed it because now i am facing a new problem and here its.

                what is a signature ?? Lol

                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