Skip to content

ECardWithTextArea

ECardWithTextArea 是一个带有文本区域的卡片容器组件,特别适合用于展示长文本内容或表单输入场景。

基本用法

qml
import "components" as Components

Components.ETheme {
    id: theme
}

Components.ECardWithTextArea {
    width: 400
    height: 300
    title: "文本区域卡片"
    
    // 文本区域的内容可以通过 content 属性设置
    content: "这是文本区域的默认内容。ECardWithTextArea 组件提供了一个带标题和文本区域的卡片容器,适合用于展示长文本或表单输入场景。"
}

属性

属性名类型默认值描述
widthreal360卡片宽度
heightreal280卡片高度
radiusreal8卡片圆角半径
backgroundColorcolortheme.surfaceColor卡片背景颜色
titlestring""卡片标题
titleColorcolortheme.textColor标题颜色
titleFontSizereal16标题字体大小
contentstring""文本区域内容
contentColorcolortheme.textSecondaryColor文本内容颜色
contentFontSizereal14文本内容字体大小
readOnlybooltrue文本区域是否只读
placeholderTextstring""文本区域占位符文本
borderWidthreal0卡片边框宽度
borderColorcolor"transparent"卡片边框颜色
shadowEnabledbooltrue是否启用阴影效果
paddingreal16卡片内边距
titleContentSpacingreal12标题与文本区域的间距

方法

方法名参数返回值描述
setTitle(title)title: stringvoid设置卡片标题
setContent(content)content: stringvoid设置文本区域内容
getContent()string获取当前文本区域内容
setReadOnly(readOnly)readOnly: boolvoid设置文本区域是否只读
setBackgroundColor(color)color: colorvoid设置卡片背景颜色

信号

信号名参数描述
contentChangedcontent: string文本区域内容变化时触发
focusedfocused: bool文本区域获取/失去焦点时触发
clicked卡片被点击时触发

示例

可编辑的文本区域卡片

qml
Components.ETheme {
    id: theme
}

Components.ECardWithTextArea {
    width: 400
    height: 300
    title: "编辑笔记"
    readOnly: false
    placeholderText: "在这里输入您的笔记..."
    content: "" // 初始为空
    
    onContentChanged: (content) => {
        console.log("笔记内容已更新:", content)
    }
}

带有提交按钮的表单卡片

qml
Components.ETheme {
    id: theme
}

Components.ECardWithTextArea {
    width: 450
    height: 350
    title: "反馈表单"
    readOnly: false
    placeholderText: "请输入您的反馈意见..."
    
    // 自定义卡片内容布局
    ColumnLayout {
        anchors.fill: parent
        anchors.margins: 16
        spacing: 16
        
        // 标题
        Text {
            text: "反馈表单"
            font.pointSize: 18
            font.bold: true
            color: theme.textColor
        }
        
        // 文本输入区域
        TextArea {
            Layout.fillWidth: true
            Layout.fillHeight: true
            placeholderText: "请输入您的反馈意见..."
            color: theme.textColor
            backgroundColor: "transparent"
            borderColor: theme.borderColor
            borderWidth: 1
            radius: 6
            padding: 12
            wrapMode: Text.WordWrap
            
            onTextChanged: {
                console.log("反馈内容:", text)
            }
        }
        
        // 提交按钮
        RowLayout {
            Layout.alignment: Qt.AlignRight
            spacing: 12
            
            Components.EButton {
                text: "取消"
                width: 100
                height: 36
                backgroundColor: "transparent"
                borderColor: theme.borderColor
                borderWidth: 1
                textColor: theme.textColor
            }
            
            Components.EButton {
                text: "提交反馈"
                width: 120
                height: 36
                backgroundColor: theme.primaryColor
                
                onClicked: {
                    console.log("反馈已提交")
                }
            }
        }
    }
}

带有格式化文本的展示卡片

qml
Components.ETheme {
    id: theme
}

Components.ECardWithTextArea {
    width: 400
    height: 300
    title: "产品说明"
    
    // 自定义内容展示
    ColumnLayout {
        anchors.fill: parent
        anchors.margins: 16
        spacing: 12
        
        Text {
            text: "产品说明"
            font.pointSize: 18
            font.bold: true
            color: theme.textColor
        }
        
        // 产品特点列表
        ColumnLayout {
            spacing: 8
            
            RowLayout {
                spacing: 8
                
                Rectangle {
                    width: 8
                    height: 8
                    color: theme.primaryColor
                    radius: 4
                    anchors.verticalCenter: parent.verticalCenter
                }
                
                Text {
                    text: "高质量材料制造"
                    color: theme.textSecondaryColor
                }
            }
            
            RowLayout {
                spacing: 8
                
                Rectangle {
                    width: 8
                    height: 8
                    color: theme.primaryColor
                    radius: 4
                    anchors.verticalCenter: parent.verticalCenter
                }
                
                Text {
                    text: "精湛工艺,细节完美"
                    color: theme.textSecondaryColor
                }
            }
            
            RowLayout {
                spacing: 8
                
                Rectangle {
                    width: 8
                    height: 8
                    color: theme.primaryColor
                    radius: 4
                    anchors.verticalCenter: parent.verticalCenter
                }
                
                Text {
                    text: "持久耐用,品质保证"
                    color: theme.textSecondaryColor
                }
            }
            
            RowLayout {
                spacing: 8
                
                Rectangle {
                    width: 8
                    height: 8
                    color: theme.primaryColor
                    radius: 4
                    anchors.verticalCenter: parent.verticalCenter
                }
                
                Text {
                    text: "7天无理由退换货"
                    color: theme.textSecondaryColor
                }
            }
        }
        
        // 价格信息
        Text {
            text: "¥ 199.00"
            font.pointSize: 24
            font.bold: true
            color: theme.primaryColor
            Layout.alignment: Qt.AlignCenter
        }
    }
}

注意事项

  • ECardWithTextArea 组件默认提供了一个带标题和文本区域的卡片容器
  • 通过设置 readOnly 属性,可以控制文本区域是否可编辑
  • 可以完全自定义卡片内容布局,实现更复杂的界面效果
  • 适合用于展示产品说明、用户反馈、笔记记录等场景
  • 在移动端使用时,建议调整卡片宽度以适应屏幕尺寸

使用 VitePress 构建