hello world
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
#include <QGuiApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QDebug>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QGuiApplication app(argc, argv);
|
||||
app.setOrganizationName("FancyInput");
|
||||
app.setApplicationName("FancyInput");
|
||||
app.setApplicationVersion("1.2.0");
|
||||
|
||||
// Qt 6 默认启用高 DPI 缩放,叠层/遮罩坐标后续用 devicePixelRatio 归一化
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
|
||||
// 关键:qt_add_qml_module 把 qmldir + QML 文件嵌入到 :/FancyInputQt/ 资源前缀下。
|
||||
// 必须把 qrc:/ 加入 import path,QML 引擎才能发现内嵌模块;
|
||||
// 否则独立运行(无 build/ 下的磁盘模块目录)会报
|
||||
// "Module FancyInputQt contains no type named Main"。
|
||||
engine.addImportPath(QStringLiteral("qrc:/"));
|
||||
|
||||
// QML 加载失败时以非零码退出(Qt 6.5+ 推荐用法)
|
||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed,
|
||||
&app, []() { QCoreApplication::exit(-1); },
|
||||
Qt::QueuedConnection);
|
||||
|
||||
engine.loadFromModule("FancyInputQt", "Main");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import FancyInput.Controls
|
||||
|
||||
// 阶段 0:Hello World 骨架
|
||||
// 窗口尺寸沿用 WPF 主窗 600x480,主题色 #651F65
|
||||
ApplicationWindow {
|
||||
id: root
|
||||
width: 600
|
||||
height: 480
|
||||
visible: true
|
||||
title: qsTr("FancyInput · Qt 迁移版(阶段 0)")
|
||||
|
||||
color: Theme.background
|
||||
|
||||
ColumnLayout {
|
||||
anchors.centerIn: parent
|
||||
spacing: 16
|
||||
|
||||
// Logo 占位:后续替换为 WPF 版图标
|
||||
Rectangle {
|
||||
Layout.preferredWidth: 96
|
||||
Layout.preferredHeight: 96
|
||||
radius: 16
|
||||
color: Theme.accent
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
|
||||
Text {
|
||||
anchors.centerIn: parent
|
||||
text: "FI"
|
||||
font.family: Theme.fontFamily
|
||||
font.pixelSize: 32
|
||||
font.bold: true
|
||||
color: "white"
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
text: qsTr("FancyInput · Hello Qt")
|
||||
font.family: Theme.fontFamily
|
||||
font.pixelSize: 24
|
||||
font.bold: true
|
||||
color: Theme.textPrimary
|
||||
}
|
||||
|
||||
Label {
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
text: qsTr("阶段 0:工程骨架跑通")
|
||||
font.family: Theme.fontFamily
|
||||
font.pixelSize: 13
|
||||
color: Theme.textSecondary
|
||||
}
|
||||
|
||||
// 验证主题单例 + 控件可用
|
||||
Button {
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
text: qsTr("点击次数:%1").arg(root.clickCount)
|
||||
font.family: Theme.fontFamily
|
||||
onClicked: {
|
||||
root.clickCount++
|
||||
console.log("点击次数:", root.clickCount)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
property int clickCount: 0
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
pragma Singleton
|
||||
import QtQuick
|
||||
|
||||
// 主题:与 WPF 版保持一致
|
||||
QtObject {
|
||||
readonly property color accent: "#651F65"
|
||||
readonly property color accentLight: "#8A3A8A"
|
||||
readonly property color background: "#1E1E24"
|
||||
readonly property color surface: "#2A2A33"
|
||||
readonly property color border: "#3A3A46"
|
||||
readonly property color textPrimary: "#F2F2F7"
|
||||
readonly property color textSecondary: "#9A9AA5"
|
||||
readonly property string fontFamily: "Cascadia Mono, Consolas, monospace"
|
||||
}
|
||||
Reference in New Issue
Block a user