nazz
nazz

Reputation: 1

Qt 4.8 Adjust window full resolution monitor

I have a widget window with a long QString, when i adjustsize() in 4K monitor the window size is 1700x500. But when using 1024x768 monitor, the window size is 850x500 when i used adjustsize(). The window sizePolicy is expanding. What function is to make my widget to use all resources in low resolution monitor? in example i want to use all width resolution, so in 1024 monitor the window width size is also as big as monitor size.

this is the code i have use

void ConfigDialog::InitializeWindowSize()
{
    QDesktopWidget desktop;
    QRect screenGeometry = QApplication::desktop()->availableGeometry(desktop.screenNumber(this));
    this->setMaximumSize(screenGeometry.width(), screenGeometry.height()); 
    this->setGeometry(0,0,screenGeometry.width(), screenGeometry.height());
    if(this->width() > 1024 && screenGeometry.width() <= 1024)
    {
        this->setGeometry(QApplication::desktop()->availableGeometry(desktop.screenNumber(this)));      
    }
    adjustSize();
}

Upvotes: 0

Views: 576

Answers (1)

Jeremy Friesner
Jeremy Friesner

Reputation: 73304

You can find out the available geometry of the screen your widget is on, by calling QDesktopWidget::availableGeometry(), as shown in the example below:

#include <QApplication>
#include <QDesktopWidget>
#include <QLabel>

int main(int argc, char ** argv)
{
   QApplication app(argc, argv);

   QLabel * lab = new QLabel("Hello!");

   lab->setGeometry(qApp->desktop()->availableGeometry(lab));  // make the label take up the entire screen!

   lab->show();

   return app.exec();
}

Upvotes: 1

Related Questions