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.
Forum Updated to NodeBB v4.3 + New Features

Not able to get screen resolution with QDesktopWidget.

Scheduled Pinned Locked Moved Unsolved General and Desktop
qdesktopwidgetresolution
7 Posts 3 Posters 5.7k 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.
  • A Offline
    A Offline
    Ahti
    wrote on 4 Apr 2017, 16:51 last edited by Ahti 4 Apr 2017, 16:53
    #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
    • H Offline
      H Offline
      hskoglund
      wrote on 4 Apr 2017, 17:03 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();
      
      A 1 Reply Last reply 5 Apr 2017, 14:03
      2
      • H hskoglund
        4 Apr 2017, 17:03

        Hi, try this:

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

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

        what is a signature ?? Lol

        H 1 Reply Last reply 6 Apr 2017, 00:23
        0
        • A Ahti
          5 Apr 2017, 14:03

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

          H Offline
          H Offline
          hskoglund
          wrote on 6 Apr 2017, 00:23 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)

          A 1 Reply Last reply 7 Apr 2017, 10:55
          2
          • H hskoglund
            6 Apr 2017, 00:23

            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)

            A Offline
            A Offline
            Ahti
            wrote on 7 Apr 2017, 10:55 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
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 7 Apr 2017, 22:06 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

              A 1 Reply Last reply 15 Apr 2017, 06:14
              1
              • S SGaist
                7 Apr 2017, 22:06

                Hi,

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

                A Offline
                A Offline
                Ahti
                wrote on 15 Apr 2017, 06:14 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