Not able to get screen resolution with QDesktopWidget.
Unsolved
General and Desktop
-
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... -
-
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)
-
Hi,
Did you update your code following @hskoglund suggestions ? If so, can you post the new version ?