boxmoe_header_banner_img

Hello! 欢迎来到csqn的个人博客!

加载中

文章导读

QT大学1


avatar
csqn 2025年12月5日 36

代码块

pragma ComponentBehavior:Bound
import QtQuick
import QtQuick.Controls.Basic

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("QT大学")

    ListModel {
        id: contectsModel // 这里的名字虽有拼写瑕疵(contacts),但不影响运行

        ListElement {
            firstName: "hello"
            lastName: "world"
            age: 1
            phoneNumber: "111-111-1111"
        }
        ListElement {
            firstName: "hello"
            lastName: "world"
            age: 1
            phoneNumber: "222-222-2222"
        }
        ListElement {
            firstName: "hello"
            lastName: "world"
            age: 1
            phoneNumber: "333-333-3333"
        }
    }

    Component {
        id: contactsDelegate

        Rectangle {
            id: delegateRect

            required property string firstName
            required property string lastName
            required property int age
            required property string phoneNumber

            height: 100
            width: parent ? parent.width : 0
            border.color: "black"

            Text {
                anchors.left: parent.left
                anchors.leftMargin: 5
                anchors.verticalCenter: parent.verticalCenter

                text: "Name: %1 %2 \nAge: %3 \nPhone: %4"
                      .arg(delegateRect.firstName)
                      .arg(delegateRect.lastName)
                      .arg(delegateRect.age)
                      .arg(delegateRect.phoneNumber)
            }
        }
    }

    ListView {
        id: contactsView
        anchors.fill: parent
        model: contectsModel
        delegate: contactsDelegate
    }
}


评论(0)

查看评论列表

暂无评论


发表评论

表情 颜文字
插入代码