QML —— Canvas重绘钟表组件(附完整源码)

发布时间:2024年01月03日
示例效果]

在这里插入图片描述

?

源码

?????main.cpp

#include <QGuiApplication>
#include <QQmlApplicationEngine>

int main(int argc, char *argv[])
{
   
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/main.qml"));
    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 2.12
import QtQuick.Window 2.12

import QtQuick.Layouts 1.12

Window
{
   
    id: root
    visible: true
    width: 800
    height: 600
    title: qsTr("Hello World")

    ColumnLayout
    {
   
        anchors.top: parent.top
        Layout.topMargin: 10
        spacing: 5

        RowLayout
        {
   
            Layout.alignment:Qt.AlignHCenter
            Text
            {
   
                text: qsTr("当前时间:")
                font.family: "微软雅黑"
                font.pixelSize: 20
            }
            Text
            {
   
                id: currentTimeID
                text: qsTr("--")
                color: "pink"
                font.family: "Courier New"
                font.pixelSize: 40
                font.bold: true
            }
        
文章来源:https://blog.csdn.net/automoblie0/article/details/135373572
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。