Linux Desktop App follow system Theme
-
Hi,
Working on a Linux Desktop Application & trying to make it follow my system Theme.
If make a Qt QWidget Application it works straight away, but how can I make it work in a
Qt Quick App (Qt 6.2, CMake, Linux, KDE) ?I have been trying QPalette... Is this even right way ?
If someone could point me in the right direction, that would be amazing -)
In the moment this is all I have:
CMakeLists.txt:
cmake_minimum_required(VERSION 3.16) project(BUL VERSION 0.1 LANGUAGES CXX) set(CMAKE_AUTOMOC ON) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 6.2 COMPONENTS Quick REQUIRED) qt_add_executable(appBUL main.cpp ) qt_add_qml_module(appBUL URI BUL VERSION 1.0 QML_FILES main.qml ) set_target_properties(appBUL PROPERTIES MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) target_link_libraries(appBUL PRIVATE Qt6::Quick) install(TARGETS appBUL BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
main.cpp:
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QIcon> // #include <QPalette> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); // app.setWindowIcon(QIcon("/images/logo_square.png")); // app.setWindowIcon(QIcon("/images/logo_square.ico")); // QGuiApplication::setWindowIcon(QIcon("/images/logo_square.png")); // app.setWindowIcon(QtGui.QIcon('/images/logo_square.png')) QQmlApplicationEngine engine; const QUrl url(u"qrc:/BUL/main.qml"_qs); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); return app.exec(); }
main.qml:
import QtQuick import QtQuick.Controls 6.3 // Added via "Design" Version 6.3 ??? ApplicationWindow { // Using ApplicationWindow instead of Window so I can use menuBar width: 1000 height: 800 visible: true title: qsTr("BUL Unofficial Linux") menuBar: MenuBar { Menu { title: qsTr("BUL") Menu { title: qsTr("Accounts") Action { text: qsTr("Online") } Action { text: qsTr("Offline") } } Action { text: qsTr("Settings") } // Action { text: qsTr("&Save") } // Action { text: qsTr("Save &As...") } MenuSeparator { } Action { text: qsTr("Quit") } } Menu { title: qsTr("Color") Action { text: qsTr("Red") } Action { text: qsTr("Green") } Action { text: qsTr("Blue") } } Menu { title: qsTr("Shape") Action { text: qsTr("Round") } Action { text: qsTr("Square") } Action { text: qsTr("Triangle") } } Menu { title: qsTr("Alerts") Action { text: qsTr("Today") } Action { text: qsTr("Yesterday") } } Menu { title: qsTr("Help") Action { text: qsTr("About") } } } }
Merci