默认情况下,Qml Controls带有一个很好的原生主题.当我通过解释器将我的程序作为qml文件运行时,它看起来很棒,但是,一旦我将我的代码复制到c后端并构建它,它看起来完全没有注意到并且非常乏味.此外,我没有启用任何类型的控件样式来取消本机外观主题.
我唯一改变的是因为我的主qml文件中的根对象是ApplicationWindow,我将main.cpp文件从加载qmlviewer更改为创建我自己的应用程序引擎.我当时认为这可能是问题,但我不确定.@H_301_3@
#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(); }
解决方法
Documentation
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.@H_301_3@
如果这对你没有帮助,我会非常惊讶.@H_301_3@