开发者

Make a Qt window autofit to the screen's size

开发者 https://www.devze.com 2023-02-04 20:48 出处:网络
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? If you want your application\

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?


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 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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消