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?
// 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.
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!
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With