add book
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
# Copyright (c) Daniel Gakwaya.
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(3-CustomComponents VERSION 0.1 LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 6.5 REQUIRED COMPONENTS Quick)
|
||||
|
||||
qt_standard_project_setup(REQUIRES 6.5)
|
||||
|
||||
qt_add_executable(app3-CustomComponents
|
||||
main.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(app3-CustomComponents
|
||||
URI 3-CustomComponents
|
||||
VERSION 1.0
|
||||
QML_FILES Main.qml MButton.qml
|
||||
)
|
||||
|
||||
set_target_properties(app3-CustomComponents 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-CustomComponents
|
||||
PRIVATE Qt6::Quick
|
||||
)
|
||||
|
||||
install(TARGETS app3-CustomComponents
|
||||
BUNDLE DESTINATION .
|
||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
)
|
||||
@@ -0,0 +1,54 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
|
||||
Item {
|
||||
id: rootId
|
||||
property alias buttonText: buttonTextId.text
|
||||
width: containerRectId.width
|
||||
height: containerRectId.height
|
||||
signal buttonClicked
|
||||
|
||||
Rectangle {
|
||||
id: containerRectId
|
||||
width: buttonTextId.implicitWidth + 20
|
||||
height: buttonTextId.implicitHeight + 20
|
||||
color: "red"
|
||||
border { color: "blue"; width : 3}
|
||||
|
||||
Text {
|
||||
id: buttonTextId
|
||||
text: "Button"
|
||||
anchors.centerIn: parent
|
||||
onTextChanged: {
|
||||
console.log("Text changed to "+ buttonTextId.text)
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
//console.log("Clicked on :"+ buttonTextId.text)
|
||||
rootId.buttonClicked()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import QtQuick
|
||||
|
||||
Window {
|
||||
visible: true
|
||||
width: 640
|
||||
height: 480
|
||||
title: qsTr("Custom Components Demo")
|
||||
|
||||
//You can change Column to Row to have rectangles laid out horizontally
|
||||
/*
|
||||
Column {
|
||||
spacing: 20
|
||||
Rectangle {
|
||||
width: 300
|
||||
height: 100
|
||||
color: "red"
|
||||
}
|
||||
Rectangle {
|
||||
width: 300
|
||||
height: 100
|
||||
color: "blue"
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
//Button code living in the main.qml file
|
||||
Rectangle {
|
||||
id: containerRectId
|
||||
color: "red"
|
||||
border {
|
||||
color: "blue"
|
||||
width: 3
|
||||
}
|
||||
|
||||
//The width and height of the rectangle depend on the dimensions of the text in buttonTextId
|
||||
width: buttonTextId.implicitWidth + 20
|
||||
height: buttonTextId.implicitHeight + 20
|
||||
|
||||
Text {
|
||||
id: buttonTextId
|
||||
text: "Button"
|
||||
anchors.centerIn: parent
|
||||
}
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
console.log("Clicked on the button")
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
MButton {
|
||||
id: button1
|
||||
buttonText: "Button1"
|
||||
}
|
||||
MButton {
|
||||
id: button2
|
||||
buttonText: "Button2"
|
||||
anchors.top: button1.bottom
|
||||
}
|
||||
*/
|
||||
|
||||
Column {
|
||||
MButton {
|
||||
buttonText: "Button1"
|
||||
onButtonClicked: {
|
||||
console.log("Clicked on button1")
|
||||
}
|
||||
|
||||
}
|
||||
MButton {
|
||||
buttonText: "Button2"
|
||||
onButtonClicked: {
|
||||
console.log("clicked on button2")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright (c) Daniel Gakwaya.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QGuiApplication app(argc, argv);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
|
||||
&app, []() { QCoreApplication::exit(-1); },
|
||||
Qt::QueuedConnection);
|
||||
engine.loadFromModule("3-CustomComponents", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
Reference in New Issue
Block a user