This commit is contained in:
2025-09-28 17:05:51 +08:00
parent 8eb80ab66d
commit d97fa3e0fe
398 changed files with 18737 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
# Copyright (c) Daniel Gakwaya.
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.16)
project(3-SettingsCustom VERSION 0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick QuickControls2)
qt_standard_project_setup(REQUIRES 6.5)
qt_add_executable(app3-SettingsCustom
main.cpp
)
qt_add_qml_module(app3-SettingsCustom
URI 3-SettingsCustom
VERSION 1.0
QML_FILES Main.qml
)
set_target_properties(app3-SettingsCustom 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(app3-SettingsCustom
PRIVATE Qt6::Quick Qt6::QuickControls2
)
install(TARGETS app3-SettingsCustom
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

View File

@@ -0,0 +1,75 @@
// Copyright (c) Daniel Gakwaya.
// SPDX-License-Identifier: MIT
import QtQuick
import QtQuick.Dialogs
import QtCore
Window {
id: rootId
visible: true
//2.Read data from the Settings object
x: windowSettingsId.x
y: windowSettingsId.y
width: windowSettingsId.width
height: windowSettingsId.height
title: qsTr("Custom Settings")
Rectangle {
id : rectId
anchors.fill: parent
//2.Read data from the Settings object
color: colorSettingsId.rectColor
MouseArea{
anchors.fill: parent
onClicked: {
colorDialogId.open()
}
ColorDialog {
id: colorDialogId
title: "Please choose a color"
onAccepted: {
console.log("The new color is: "+ selectedColor)
rectId.color = selectedColor
}
onRejected: {
console.log("Canceled")
}
}
}
}
//1. Don't use property aliases in the Settings objects
Settings{
id: windowSettingsId
category: "window"
property int x: 300
property int y: 300
property int width: 640
property int height: 480
}
Settings{
id: colorSettingsId
category: "colors"
property color rectColor: "red"
}
//3.Save the data when the Window object is about to die
Component.onDestruction: {
//Save the window properties
windowSettingsId.x = rootId.x
windowSettingsId.y = rootId.y
windowSettingsId.width = rootId.width
windowSettingsId.height = rootId.height
//Save the color property
colorSettingsId.rectColor = rectId.color
}
}

View File

@@ -0,0 +1,28 @@
// Copyright (c) Daniel Gakwaya.
// SPDX-License-Identifier: MIT
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQuickStyle>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQuickStyle::setStyle("Basic");
//App Information
app.setOrganizationName("LearnQt2");
app.setOrganizationDomain("learnqts.guide");
app.setApplicationName("SettingsDemos");
QQmlApplicationEngine engine;
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
&app, []() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
engine.loadFromModule("3-SettingsCustom", "Main");
return app.exec();
}