在Qt Qml控件,ApplicationWindow缺乏本机主题运行时 [英] In Qt Qml Controls, ApplicationWindow lacks the native-looking theme when run

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

问题描述

Qml控件在默认情况下提供了一个很好的类似native的主题。当我通过解释器运行我的程序作为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控件,ApplicationWindow缺乏本机主题运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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