Hi,
I am using the following function to return screen size:
screenWidth = screen->availableSize().width();
screenHeight = screen->availableSize().height();
QScreen *screen = QApplication::screens().at(0);
screenWidth = screen->availableSize().width();
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.
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
screenWidth = screen->availableSize().width();
screenHeight = screen->availableSize().height();
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QScreen *screen = QApplication::screens().at(0);
screenWidth = screen->availableSize().width();
screenHeight = screen->availableSize().height();
}
To copy to clipboard, switch view to plain text mode
Any help would be greatly appreciated, thank you .
Bookmarks