Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a Qt window autofit to the screen's size

I have a Qt application which needs to be loaded on mobile devices of different screen sizes. How do I make it autofit to the mobile device's screen size?

like image 446
Owen Avatar asked Jan 14 '11 09:01

Owen


People also ask

How do I resize a window in Qt?

// In your constructor for QMainWindow glw = new QGLWidget; this->setCentralWidget(glw); glw->setFixedSize(500, 500); this->adjustSize(); Hope that helps. While this really resizes the window to the needed size it prevents from further resizing by the user.

How do you set auto resize GUI in Qt depending on the screen size?

In Designer, activate the centralWidget and assign a layout, e.g. horizontal or vertical layout. Then your QFormLayout will automatically resize. Always make sure, that all widgets have a layout! Otherwise, automatic resizing will break with that widget!


1 Answers

If you want your application's main window to occupy the whole screen as soon as it starts, use QWidget::showMaximized, e.g.

int main(int argc, char **argv)
{
    QApplication app(argc, argv);
    MyMainWidget widget;
    widget.showMaximized();
    return app.exec();
}

Note that showMaximized is a convenience function which internally calls the QWidget::setWindowState mentioned by Andrew:

void QWidget::showMaximized()
{
    // ...
    setWindowState((windowState() & ~(Qt::WindowMinimized | Qt::WindowFullScreen))
                   | Qt::WindowMaximized);
    show();
}
like image 135
Gareth Stockwell Avatar answered Nov 16 '22 07:11

Gareth Stockwell