This commit is contained in:
2025-09-28 17:03:21 +08:00
parent 4856db17ee
commit 8eb80ab66d
11 changed files with 514 additions and 0 deletions

42
4DemoApp/CMakeLists.txt Normal file
View File

@@ -0,0 +1,42 @@
cmake_minimum_required(VERSION 3.16)
project(4DemoApp VERSION 0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 REQUIRED COMPONENTS Quick)
qt_standard_project_setup(REQUIRES 6.5)
qt_add_executable(app4DemoApp
main.cpp
)
qt_add_qml_module(app4DemoApp
URI 4DemoApp
VERSION 1.0
QML_FILES
Main.qml MButton.qml
)
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
set_target_properties(app4DemoApp PROPERTIES
# MACOSX_BUNDLE_GUI_IDENTIFIER com.example.app4DemoApp
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(app4DemoApp
PRIVATE Qt6::Quick
)
include(GNUInstallDirs)
install(TARGETS app4DemoApp
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

70
4DemoApp/MButton.qml Normal file
View File

@@ -0,0 +1,70 @@
import QtQuick
Item {
id: rootId
property alias buttonText: buttonTextId.text
width: containerRectId.width
height: containerRectId.height
signal buttonClicked
Rectangle {
id: containerRectId
signal greet(string message)
color: "red"
border {
color: "blue"
width: 3
}
width: buttonTextId.implicitWidth + 20
height: buttonTextId.implicitHeight + 20
Text {
id: buttonTextId
text: "MButton"
anchors.centerIn: parent
}
MouseArea {
id: mouseAreaId
anchors.fill: parent
hoverEnabled: true
// onClicked: {
// // console.log("Clicked on button" + buttonTextId.text)
// rootId.buttonClicked()
// }
// onClicked: function(mouse) {
// console.log(mouse.x)
// }
// onClicked: (mouse_param) => console.log(mouse_param.x)
// onEntered: {
// console.log("enter")
// }
}
onGreet: function(message) {
console.log("Greeting with message: " + message);
}
function respond_your_way(message) {
console.log("Responding our way;Greeting with message: " + message);
}
Connections {
target: mouseAreaId
function onClicked() {
// console.log("Hello")
containerRectId.greet("Hello Lenn")
}
function onDoubleClicked(mouse) {
console.log("DoubleClicked at: " + mouse.x)
}
}
Component.onCompleted: {
containerRectId.greet.connect(containerRectId.respond_your_way)
}
}
}

69
4DemoApp/Main.qml Normal file
View File

@@ -0,0 +1,69 @@
import QtQuick
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
// Item {
// id: containerItemId
// x: 50
// y: 50
// width: 600
// height: 300
// Rectangle {
// anchors.fill: parent
// color: "beige"
// // border.color: "black"
// // border.width: 10
// border {
// color: "black"
// width: 10
// }
// }
// Rectangle {
// x: 0
// y: 10
// width: 50
// height: 50
// color: "red"
// }
// Rectangle {
// x: 60
// y: 10
// width: 50
// height: 50
// color: "green"
// }
// Image {
// x: 150
// y:50
// width: 100
// height: 100
// // source: "qrc:/...."
// }
// }
MButton {
id: button1
buttonText: "Button1"
// color: "grey"
onButtonClicked: {
console.log("Clicked on button1")
}
}
MButton {
id: button2
anchors.top: button1.bottom
buttonText: "Button2"
// color: "yellow"
onButtonClicked: {
console.log("Clicked on button1")
}
}
}

18
4DemoApp/main.cpp Normal file
View File

@@ -0,0 +1,18 @@
#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("4DemoApp", "Main");
return app.exec();
}