问题描述
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();
}
推荐答案
如果这不会帮助你,我会非常惊讶。
If this will not help you I will be terribly suprised.
这篇关于在Qt Qml控件,ApplicationWindow缺乏本机主题运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!