Make a Qt window autofit to the screen's size

三世轮回 提交于 2019-12-18 14:38:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!