Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Qt Qml Controls, ApplicationWindow lacks the native-looking theme when run

Tags:

c++

qt

qt5

qml

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.

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();
}
like image 970
user2887117 Avatar asked Feb 14 '14 03:02

user2887117


1 Answers

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.

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

like image 101
Kakadu Avatar answered Sep 20 '22 10:09

Kakadu