Fabio
Fabio

Reputation: 2602

QML application style

I'm writing an application for tablet using QML.

The main QML file of the application is something like this:

ApplicationWindow {
    id: mainWindow
    visible: true
    title: "MyApp"

    menuBar: MenuBar {
        Menu {
            title: qsTr("File")
            MenuItem {
                text: qsTr("Open project")
            }
            MenuItem {
                text: qsTr("Exit")
                onTriggered: Qt.quit();
            }
        }
    }
}

If I run the app on an Android device, the menu is styled like a standard Android menu, that is a button (with the "3 points" icon) on the top right corner. This is very good.

Instead if I run the app on a Windows device, the menu is like a standard desktop application menu (the traditional file menu...). This style is not suitable for a tablet application.

There is a way to choose the style of the application? Thanks!

Upvotes: 2

Views: 1942

Answers (2)

Mitch
Mitch

Reputation: 24416

The correct style should be picked up by default. If it's not, it means that a style for that device type (e.g. touch) isn't available. If you want to use a specific style, you can set the QT_QUICK_CONTROLS_STYLE environment variable before running your application. However, some styles can only be run on the platform they are built for. For example, the Android style needs a specific file from a directory on the device in order to function properly.

Note that Qt Quick Controls have a stronger focus on desktop. If you have the opportunity, and you do not need a native style, I'd recommend trying out Qt Labs Controls. They are more touch-oriented, and have a style that implements Microsoft's Universal Design Guidelines.

enter image description here

They currently have three different styles available, and any style can be used on any platform.

Upvotes: 3

Abdiel
Abdiel

Reputation: 81

Without styling, components from Qt Quick Controls are supposed have a native look. You can make your own styles for almost all of them, though.

Upvotes: 2

Related Questions