在 Qt Qml Controls 中,ApplicationWindow 在运行时缺少原生主题 [英] In Qt Qml Controls, ApplicationWindow lacks the native-looking theme when run

查看:22
本文介绍了在 Qt Qml Controls 中,ApplicationWindow 在运行时缺少原生主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Qml Controls 默认带有一个不错的原生主题.当我通过解释器将我的程序作为 qml 文件运行时,它看起来很棒,但是,一旦我将我的代码复制到 c++ 后端并构建它,它看起来完全没有主题并且非常平淡.此外,我没有启用任何类型的控制样式来使原生主题无效.

Qml Controls comes with a nice native-like theme by default. When I run my program as qml files through the interpreter, it looks great, however, once I copy my code over to c++ backend and build it, it looks completely unthemed and very bland. Also I did not enable any sort of Control Styles to void the native looking theme.

我唯一改变的是因为我的主 qml 文件中的根对象是一个 ApplicationWindow,我将 main.cpp 文件从加载 qmlviewer 更改为创建我自己的应用程序引擎.我在想这可能是问题,但我不确定.

The only thing that I changed was since my root object in my main qml file is a ApplicationWindow, I changed the main.cpp file from loading qmlviewer, to creating my own application engine. I was thinking that this might be the issue but i'm not sure.

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickWindow>

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

    engine.load(QUrl("src/qml/main.qml"));
    QObject *topLevel = engine.rootObjects().value(0);
    QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);

    window->show();
    return app.exec();
}

推荐答案

文档

在这个例子中我们使用的是 QApplication 而不是 QGuiApplication.尽管您可以改用 QGuiApplication,但这样做会消除依赖于平台的样式.这是因为它依赖于小部件模块来提供原生外观.

We are using QApplication and not QGuiApplication in this example. Though you can use QGuiApplication instead, doing this will eliminate platform-dependent styling. This is because it is relying on the widget module to provide the native look and feel.

如果这对你没有帮助,我会感到非常惊讶.

If this will not help you I will be terribly suprised.

这篇关于在 Qt Qml Controls 中,ApplicationWindow 在运行时缺少原生主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆