You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何让iPad上的Qt/QML应用以实际尺寸(500x500)运行而非全屏

Fixing Qt/QML App to Run at Exact 500x500 Size on iPad

Hey there! I’ve dealt with this exact frustration when deploying Qt/QML apps to iOS devices—Qt tends to default to fullscreen on iPad, overriding your explicit window size settings. Let’s break down the steps to get your app running at the intended 500x500 resolution:

1. Lock Window Dimensions in QML

First, make sure your root window explicitly enforces its size and prevents resizing. Use ApplicationWindow (preferred over Window for iOS) and set fixed min/max dimensions:

ApplicationWindow {
    id: mainWindow
    width: 500
    height: 500
    minimumWidth: 500
    minimumHeight: 500
    maximumWidth: 500
    maximumHeight: 500
    visible: true

    // Force size on iOS in case initial settings are overridden
    Component.onCompleted: {
        if (Qt.platform.os === "ios") {
            mainWindow.width = 500;
            mainWindow.height = 500;
        }
    }
}

2. Disable iOS Fullscreen Requirement

iOS apps default to fullscreen unless told otherwise. You’ll need to modify the Info.plist file for your iOS build:

  • If you don’t have a custom Info.plist, create one in your project’s iOS folder.
  • Add these keys to disable forced fullscreen and set preferred content size:
<key>UIRequiresFullScreen</key>
<false/>
<key>UIApplicationSceneManifest</key>
<dict>
    <key>UIApplicationSupportsMultipleScenes</key>
    <true/>
    <key>UISceneConfigurations</key>
    <dict>
        <key>UIWindowSceneSessionRoleApplication</key>
        <array>
            <dict>
                <key>UISceneConfigurationName</key>
                <string>Default Configuration</string>
                <key>UISceneDelegateClassName</key>
                <string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
                <key>UISceneStoryboardFile</key>
                <string>Main</string>
                <key>UISceneSettings</key>
                <dict>
                    <key>UIScenePreferredContentSize</key>
                    <string>{500, 500}</string>
                </dict>
            </dict>
        </array>
    </dict>
</dict>
  • Link this custom plist in your .pro file to ensure it’s used during builds:
ios {
    QMAKE_INFO_PLIST = ios/Info.plist
}

3. Disable High-DPI Scaling (If Needed)

Qt’s high-DPI scaling can sometimes stretch your window to fit the screen. If you want pixel-perfect 500x500 rendering, disable it in your main.cpp:

#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    // Disable auto-scaling to match your exact window size
    app.setAttribute(Qt::AA_DisableHighDpiScaling);
    // Optional: Keep high-DPI support for pixmaps while disabling window scaling
    app.setAttribute(Qt::AA_UseHighDpiPixmaps);

    QQmlApplicationEngine engine;
    const QUrl url(u"qrc:/main.qml"_qs);
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                     &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);

    return app.exec();
}

4. Verify Qt Creator Deployment Settings

Double-check your project’s iOS deployment configuration in Qt Creator:

  • Go to Projects > iOS > Run
  • Look for any "Full Screen" checkbox or setting and uncheck it
  • Ensure the "Window Size" option is set to your custom 500x500 dimensions

After applying these changes, rebuild and redeploy your app to iPad—it should now render at exactly 500x500 instead of filling the entire screen.

内容的提问来源于stack exchange,提问作者Vineesh TP

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 06:38:15