问题
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?
回答1:
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();
}
回答2:
If you really want the geometry, you could use QDesktopWidget to get information about the display, including the geometry of it.
If you just want the window to be sized properly, however, you should use QWidget::setWindowState, as Andrew suggested.
回答3:
void QWidget::setWindowState ( Qt::WindowStates windowState )
Sets the window state to windowState. The window state is a OR'ed combination of Qt::WindowState: Qt::WindowMinimized, Qt::WindowMaximized, Qt::WindowFullScreen, and Qt::WindowActive.
From documentation of QWidget. Hope it will help
来源:https://stackoverflow.com/questions/4689453/make-a-qt-window-autofit-to-the-screens-size