HusTransfer 穿梭框

August 13, 2026 · View on GitHub

← 返回主目录

← 返回本类别目录

HusTransfer 穿梭框

双栏穿梭选择框。

  • 模块 { HuskarUI.Basic }

  • 继承自 { Control }


支持的代理:

  • titleDelegate: Component 标题代理,代理可访问属性:

    • title: string 标题文本
  • searchInputDelegate: Component 搜索输入框代理。

  • leftActionDelegate: Component 向左动作代理。

  • rightActionDelegate: Component 向右动作代理。

  • emptyDelegate: Component 空状态代理。


支持的属性:

属性名类型默认值描述
dataSourcearray[]数据源
sourceKeysarray(readonly)[]左侧数据的 key 集合
targetKeysarray[]右侧框数据的 key 集合(左侧将根据此自动计算)
sourceCheckedKeysarray[]左侧选中的键列表
targetCheckedKeysarray[]右侧选中的键列表
defaultSourceCheckedKeysarray[]左侧默认选中的键列表
defaultTargetCheckedKeysarray[]右侧默认选中的键列表
sourceCheckedCountint(readonly)-左侧选中的数量
targetCheckedCountint(readonly)-右侧选中的数量
titlesarray['Source', 'Target']标题列表,顺序从左至右
operationsarray['>', '<']操作文案集合,顺序从左至右
showSearchboolfalse是否显示搜索框
filterOptionfunction(value, record)-输入项将使用该函数进行筛选(showSearch需为true)
searchPlaceholderstring'Search here'搜索框占位符
paginationbool丨objectfalse是否使用分页样式
oneWayboolfalse是否单向穿梭
titleFontfont-标题文本
colorTitlecolor-标题颜色
colorTextcolor-项文本颜色
colorBgcolor-背景颜色
radiusBgHusRadius-背景圆角
borderBgHusBorder-背景边框
sourceTableViewHusTableView-访问内部左侧表格视图
targetTableViewHusTableView-访问内部右侧表格视图

{dataSource}支持的属性:

属性名类型可选/必选描述
keystring必选数据键
titlestring必选标题
enabledbool可选是否启用

支持的函数:

  • clearAllCheckedKeys(direction: string = 'left') 清除 direction 指定方向的所有选中键。

  • filter(text: string, direction: string = 'left') 使用 textdirection 指定方向的数据执行过滤。


支持的信号:

  • change(nextTargetKeys: var, direction: string, moveKeys: var) 选项在两栏之间转移时发出

代码演示

示例 1 - 基本用法

最基本的用法,展示了 dataSourcetargetKeysdefaultTargetCheckedKeys 的用法。

import QtQuick
import HuskarUI.Basic

Column {
    spacing: 10

    HusTransfer {
        width: 400
        height: 200
        dataSource: [
            { key: '1', title: 'Content 1' },
            { key: '2', title: 'Content 2', enabled: false },
            { key: '3', title: 'Content 3' },
            { key: '4', title: 'Content 4' },
            { key: '5', title: 'Content 5' },
            { key: '6', title: 'Content 6' },
            { key: '7', title: 'Content 7' },
            { key: '8', title: 'Content 8' },
        ]
        targetKeys: ['3', '4', '5']
        defaultTargetCheckedKeys: ['3', '4']
    }
}

示例 2 - 带搜索框

通过 showSearch 设置为 true 显示搜索框。

通过 filterOption 设置过滤选项,它是形如:function(value: string, record: var): bool { } 的函数。

import QtQuick
import HuskarUI.Basic

Column {
    spacing: 10

    HusTransfer {
        width: 400
        height: 200
        titles: ['Source', 'Target']
        showSearch: true
        dataSource: {
            const data = [];
            for (let i = 0; i < 20; i++) {
                data.push({
                    key: i.toString(),
                    title: 'Content ' + (i + 1),
                    description: 'Description of content ' + (i + 1),
                    enabled: i % 3 !== 0
                });
            }
            return data;
        }
        targetKeys: ['1', '4']
    }
}

示例 3 - 分页

大数据下使用分页。

通过 pagination 设置为 object 显示为分页格式。

pagination 对象支持的属性有:

  • defaultButtonSpacing 按钮间隔。

  • pageSize 每页数量。

  • pageButtonMaxCount 最大页按钮数。

  • showQuickJumper 是否显示快速跳转。

详细说明见 HusPagination

import QtQuick
import HuskarUI.Basic

Column {
    spacing: 10

    HusTransfer {
        width: 800
        height: 300
        titles: ['Source', 'Target']
        showSearch: true
        dataSource: {
            const data = [];
            for (let i = 0; i < 1000; i++) {
                data.push({
                    key: i.toString(),
                    title: 'Content ' + (i + 1),
                    description: 'Description of content ' + (i + 1),
                    enabled: i % 3 !== 0
                });
            }
            return data;
        }
        targetKeys: ['1', '4', '9']
        pagination: ({
                         pageSize: 100,
                         pageButtonMaxCount: 5
                     })
    }
}