Hi,

I am using the following function to return screen size:

Qt Code:
  1. QScreen *screen = QApplication::screens().at(0);
  2. screenWidth = screen->availableSize().width();
  3. screenHeight = screen->availableSize().height();
To copy to clipboard, switch view to plain text mode 

I tested this code by making a push button and on the button click, it runs this code and it works. Although when I try putting this code in my constructor function, it keeps returning screenWidth = 0 and screenHeight = 0.

Qt Code:
  1. MainWindow::MainWindow(QWidget *parent) :
  2. QMainWindow(parent),
  3. ui(new Ui::MainWindow)
  4. {
  5. ui->setupUi(this);
  6.  
  7. QScreen *screen = QApplication::screens().at(0);
  8. screenWidth = screen->availableSize().width();
  9. screenHeight = screen->availableSize().height();
  10. }
To copy to clipboard, switch view to plain text mode 

Any help would be greatly appreciated, thank you .