DelegateChooser QML Type

뷰에서 모델의 여러 항목 유형에 대해 서로 다른 델리게이트를 사용할 수 있습니다. 자세히...

Import Statement: import Qt.labs.qmlmodels

속성

상세 설명

DelegateChooser는 뷰에 컴포넌트가 필요하고 델리게이트로 사용되는 시나리오를 위한 특수 Component 유형입니다. DelegateChooser는 DelegateChoice의 집합을 캡슐화합니다. 이러한 선택 사항은 모델의 각 항목에 대해 인스턴스화될 델리게이트를 결정하는 데 사용됩니다. 선택 항목의 선택은 모델 항목이 role 에 대해 갖는 값과 인덱스에 따라 수행됩니다.

DelegateChooser는 일반적으로 뷰에서 서로 크게 다른 델리게이트 집합을 표시해야 할 때 사용됩니다. 예를 들어 일반적인 전화 설정 보기에는 토글 스위치, 슬라이더, 라디오 버튼 및 각 설정의 유형에 따른 기타 시각화가 포함될 수 있습니다. 이 경우 DelegateChooser는 각 설정에 서로 다른 유형의 위임자를 쉽게 연결할 수 있는 방법을 제공할 수 있습니다:

import QtQuick
import QtQuick.Controls
import Qt.labs.qmlmodels

ListView {
    width: 200; height: 400

    ListModel {
        id: listModel
        ListElement { type: "info"; ... }
        ListElement { type: "switch"; ... }
        ListElement { type: "swipe"; ... }
        ListElement { type: "switch"; ... }
    }

    DelegateChooser {
        id: chooser
        role: "type"
        DelegateChoice { roleValue: "info"; ItemDelegate { ... } }
        DelegateChoice { roleValue: "switch"; SwitchDelegate { ... } }
        DelegateChoice { roleValue: "swipe"; SwipeDelegate { ... } }
    }

    model: listModel
    delegate: chooser
}

참고: 이 유형은 TableViewDelegateModel 기반 보기에서만 투명하게 작동하도록 고안되었습니다. 내부적으로 DelegateModel 기반이 아닌 보기(사용자 정의 보기 포함)가 설명된 대로 작동하려면 이 유형의 구성 요소를 명시적으로 지원해야 합니다.

DelegateChoice참조하세요 .

속성 문서

choices : list<DelegateChoice> [default]

선택자에 대한 델리게이트 선택 목록입니다.

이 목록은 정렬된 목록으로 취급되며, 일치하는 첫 번째 DelegateChoice 가 보기로 사용됩니다.

choices 속성은 DelegateChooser 의 기본 속성이므로 모든 하위 항목이 이 속성에 자동으로 할당되므로 일반적으로 속성을 참조할 필요는 없습니다.


role : string

이 속성은 주어진 모델 항목의 대리인을 결정하는 데 사용되는 역할 또는 속성 이름을 보유합니다.

참고: ListModel 을 포함한 QAbstractItemModel 기반 모델의 경우 모델에서 역할이 변경되었다는 신호를 보내면 DelegateChooser 에서 선택 항목을 다시 평가합니다. 다른 유형의 모델의 경우 이 선택은 주어진 모델 인덱스에 대한 항목이 생성될 때 한 번만 수행됩니다.

DelegateChoice도 참조하세요 .


© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.