QQuick with CMake: style doesn't work

I am ready to use the style in Qt Quick Controls 2 and with the CMake project in C ++. And it's hard for me to find the right colors.

C ++, qml and styling code comes from the qt blog and works fine while I use .pro , but when I go to CMakeLists.txt, I can’t get the correct colors (I think they are dark / purple by default rather than dark / orange).

In the .pro project, my main.cpp looks like this:

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickStyle>

int main(int argc, char *argv[])
{
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QGuiApplication app(argc, argv);

    QQuickStyle::setStyle("Material");

    QQmlApplicationEngine engine;
    engine.load(QUrl(QLatin1String("qrc:/main.qml")));

    return app.exec();
}

My qml.qrc file looks like this:

<!DOCTYPE RCC>
<RCC>
    <qresource prefix="/">
        <file>main.qml</file>
        <file>CustomLabel.qml</file>
        <file>PageBackground.qml</file>
        <file>SideBar.qml</file>
        <file>SideBarForm.ui.qml</file>
        <file>Light.qml</file>
        <file>LightForm.ui.qml</file>
        <file>Heating.qml</file>
        <file>HeatingForm.ui.qml</file>
        <file>Security.qml</file>
        <file>SecurityForm.ui.qml</file>
        <file>qtquickcontrols2.conf</file>
    </qresource>
</RCC>

And my qtquickcontrols2.conf file :

[Controls]
Style=Material

[Universal]
Theme=Dark
Accent=DeepOrange

[Material]
Theme=Dark
Accent=DeepOrange

CMake ( .pro), , .pri .pro, CMakeLists.txt, :

CMAKE_MINIMUM_REQUIRED(VERSION 2.8.9)
cmake_policy(SET CMP0015 NEW)

# Projet. 
project(MyQtQuick)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

# Find dependencies.
set(QT_DIR ../DevRoot/Dependencies/Qt/v5.7.0/5.7/gcc_64)

# Prepare project for Qt. 
set(CMAKE_INCLUDE_CURRENT_DIR ON) # Find includes in corresponding build directories.
set(CMAKE_AUTOMOC ON) # Instruct CMake to run moc automatically when needed.
set(CMAKE_PREFIX_PATH ${QT_DIR})

find_package(Qt5Widgets)
find_package(Qt5Core)
find_package(Qt5Gui)
find_package(Qt5OpenGL)
find_package(Qt5Quick REQUIRED)
find_package(Qt5Qml REQUIRED)
find_package(Qt5QuickControls2 REQUIRED)

# List sources.
set(${PROJECT_NAME}_sources
    main.cpp
)

qt5_add_resources(RCC_SOURCES qml.qrc)

# Headers.
include_directories(
    .
    )

# Output library.
add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_sources})

# Linker.
qt5_use_modules(${PROJECT_NAME} Core Gui OpenGL QuickControls2)

main.cpp, qml.qrc **** qtquickcontrols2.conf ** ( main.qml main.cpp, "qrc:/main.qml" "../main.qml" * * qrc: CMake - ).

, CMake, , , / , / qtquickcontrols2.conf. .pro , .

. , QQuickView, QQmlApplicationEngine qml ( , , ), .

- , CMake?

( ): , "qrc:/main.qml" CMake? .pro "qrc:/main.qml" , qml .qrc , CMake.

+4

Source: https://habr.com/ru/post/1648235/


All Articles