HusRadioBlock 单选块(HusRadio变种)

September 5, 2026 · View on GitHub

← 返回主目录

← 返回本类别目录

HusRadioBlock 单选块(HusRadio变种)

用于在多个备选项中选中单个状态。

  • 模块 { HuskarUI.Basic }

  • 继承自 { Control }


支持的代理:

  • toolTipDelegate: Component 文字提示代理,代理可访问属性:

    • checked: int 是否选中

    • pressed: int 是否按下

    • hovered: int 是否悬浮

    • toolTip: var 文字提示数据

  • radioDelegate: Component 单选项代理,代理可访问属性:

    • index: int 单选项索引

    • modelData: var 单选项数据


支持的属性:

属性名类型默认值描述
animationEnabledboolHusTheme.animationEnabled是否开启动画
effectEnabledbooltrue是否开启点击效果
hoverCursorShapeenumQt.PointingHandCursor悬浮时鼠标形状(来自 Qt.*Cursor)
modelarray[]单选块模型
countintmodel.length单选数量
initCheckedIndexint-1初始选择的单选项索引
currentCheckedIndexint-1当前选择的单选项索引
currentCheckedValue(readonly)varundefined当前选择的单选项的值
typeenumHusRadioBlock.Type_Filled单选项类型(来自 HusRadioBlock)
sizeenumHusRadioBlock.Size_Auto单选项大小(来自 HusRadioBlock)
radioWidthint120单选项宽度(size == HusRadioBlock.Size_Fixed 生效)
radioHeightint30单选项高度(size == HusRadioBlock.Size_Fixed 生效)
radiusBgHusRadius-单选项背景圆角
contentDescriptionstring''内容描述(提高可用性)

模型支持的属性:

属性名类型可选/必选描述
labelstring必选本单选项的标签
valuesting可选本单选项的值
enabledvar可选本单选项是否启用
iconSourceint丨string可选本按钮图标(参见 HusIcon)或图标链接
toolTipvar可选存在时则创建文字提示
toolTip.textstring可选存在时则创建文字提示
toolTip.delayint可选文字提示延时(ms)
toolTip.timeoutint可选文字提示超时(ms)

支持的函数:

  • setCurrentIndex(index: int) 设置当前的索引为 index

支持的信号:

  • clicked(index: int, radioData: var) 点击单选项时发出

    • index 单选项索引

    • radioData 单选项数据


代码演示

示例 1

通过 model 属性设置初始单选块的模型,单选项支持的属性:

  • { label: 本单选项的标签 }

  • { value: 本单选项的值 }

  • { enabled: 本单选项是否启用 }

  • { iconSource: 本单选项图标 }

通过 type 属性设置单选块的类型,支持的类型:

  • 填充样式的按钮(默认) { HusRadioBlock.Type_Filled }

  • 线框样式的按钮(无填充) { HusRadioBlock.Type_Outlined }

import QtQuick
import HuskarUI.Basic

Column {
    spacing: 10

    HusRadioBlock {
        initCheckedIndex: 0
        model: [
            { label: 'Apple', value: 'Apple' },
            { label: 'Pear', value: 'Pear' },
            { label: 'Orange', value: 'Orange' },
            { iconSource: HusIcon.QuestionOutlined, value: 'HusIcon.QuestionOutlined' },
        ]
    }

    HusRadioBlock {
        initCheckedIndex: 1
        type: HusRadioBlock.Type_Outlined
        model: [
            { label: 'Apple', value: 'Apple' },
            { label: 'Pear', value: 'Pear' },
            { label: 'Orange', value: 'Orange' },
            { iconSource: HusIcon.QuestionOutlined, value: 'HusIcon.QuestionOutlined' },
        ]
    }

    HusRadioBlock {
        initCheckedIndex: 2
        model: [
            { label: 'Apple', value: 'Apple' },
            { label: 'Pear', value: 'Pear', enabled: false },
            { label: 'Orange', value: 'Orange' },
        ]
    }

    HusRadioBlock {
        enabled: false
        initCheckedIndex: 2
        model: [
            { label: 'Apple', value: 'Apple' },
            { label: 'Pear', value: 'Pear', enabled: false },
            { label: 'Orange', value: 'Orange' },
        ]
    }
}

示例 2

通过 size 属性设置单选块调整大小的模式,支持的大小:

  • 自动计算大小(默认) { HusRadioBlock.Size_Auto }

  • 固定大小(将使用radioWidth/radioHeight) { HusRadioBlock.Size_Fixed }

import QtQuick
import HuskarUI.Basic

Column {
    spacing: 10

    HusRadioBlock {
        initCheckedIndex: 0
        size: HusRadioBlock.Size_Fixed
        model: [
            { label: 'Apple', value: 'Apple' },
            { label: 'Pear', value: 'Pear' },
            { label: 'Orange', value: 'Orange' },
        ]
    }

    HusRadioBlock {
        initCheckedIndex: 0
        size: HusRadioBlock.Size_Auto
        type: HusRadioBlock.Type_Outlined
        model: [
            { label: 'Apple', value: 'Apple' },
            { label: 'Pear', value: 'Pear' },
            { label: 'Orange', value: 'Orange' },
        ]
    }
}