QAbstractListModel Class

QAbstractListModel 클래스는 1차원 목록 모델을 생성하기 위해 서브클래싱할 수 있는 추상 모델을 제공합니다. 더 보기...

Header: #include <QAbstractListModel>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
상속합니다: QAbstractItemModel
상속받습니다:

QPdfLinkModel, QPdfSearchModel, QStringListModel, QVirtualKeyboardSelectionListModel, 그리고 QWebEngineHistoryModel

공용 함수

QAbstractListModel(QObject *parent = nullptr)
virtual ~QAbstractListModel()

재구현된 공용 함수

virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
virtual Qt::ItemFlags flags(const QModelIndex &index) const override
virtual QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override
virtual QModelIndex sibling(int row, int column, const QModelIndex &idx) const override

상세 설명

QAbstractListModel은 데이터를 단순한 비계층적 항목의 시퀀스로 표현하는 모델에 대한 표준 인터페이스를 제공합니다. 직접 사용되지는 않지만 반드시 서브클래싱되어야 합니다.

이 모델은 QAbstractItemModel 보다 더 전문화된 인터페이스를 제공하므로 트리 뷰와 함께 사용하기에는 적합하지 않으며, 해당 용도의 모델을 제공하려면 QAbstractItemModel 을 서브클래스화해야 합니다. 데이터를 관리하기 위해 여러 목록 모델을 사용해야 하는 경우에는 QAbstractTableModel 을 서브클래스하는 것이 더 적합할 수 있습니다.

이 클래스를 서브클래싱하고 필요한 최소한의 함수를 구현하여 간단한 모델을 만들 수 있습니다. 예를 들어 QListView 위젯에 문자열 목록을 제공하는 간단한 읽기 전용 QStringList 기반 모델을 구현할 수 있습니다. 이 경우 목록의 항목 수를 반환하는 rowCount() 함수와 목록에서 항목을 검색하는 data() 함수만 구현하면 됩니다.

모델은 1차원 구조를 나타내므로 rowCount() 함수는 모델에 있는 총 항목 수를 반환합니다. columnCount () 함수는 모든 종류의 뷰와의 상호 운용성을 위해 구현되었지만 기본적으로 모델에 열이 하나만 포함되어 있음을 뷰에 알립니다.

하위 클래스

QAbstractListModel을 서브클래싱할 때는 rowCount() 및 data() 함수의 구현을 제공해야 합니다. 잘 동작하는 모델은 headerData() 구현도 제공합니다.

모델이 QML 내에서 사용되며 roleNames() 함수에서 제공하는 기본 역할 이외의 역할이 필요한 경우, 이를 재정의해야 합니다.

편집 가능한 목록 모델의 경우 setData() 구현도 제공하고 flags() 함수가 Qt::ItemIsEditable 를 포함하는 값을 반환하도록 구현해야 합니다.

QAbstractListModel은 이 모델에 항목의 열이 하나만 있음을 뷰에 알리는 columnCount()의 기본 구현을 제공한다는 점에 유의하세요.

크기 조정이 가능한 목록형 데이터 구조에 대한 인터페이스를 제공하는 모델은 insertRows() 및 removeRows()의 구현을 제공할 수 있습니다. 이러한 함수를 구현할 때는 연결된 모든 뷰가 변경 사항을 인식할 수 있도록 적절한 함수를 호출하는 것이 중요합니다:

참고: 모델 서브클래싱에 대한 몇 가지 일반적인 지침은 모델 서브클래싱 참조에서 확인할 수 있습니다.

모델 클래스, 모델 서브클래싱 참조, QAbstractItemView, 및 QAbstractTableModel참조하세요 .

멤버 함수 문서

[explicit] QAbstractListModel::QAbstractListModel(QObject *parent = nullptr)

주어진 parent 으로 추상 목록 모델을 구축합니다.

[virtual noexcept] QAbstractListModel::~QAbstractListModel()

추상 목록 모델을 삭제합니다.

[override virtual] bool QAbstractListModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)

재구현합니다: QAbstractItemModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent).

[override virtual] Qt::ItemFlags QAbstractListModel::flags(const QModelIndex &index) const

재구현합니다: QAbstractItemModel::flags(const QModelIndex &index) const.

[override virtual] QModelIndex QAbstractListModel::index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const

재구현합니다: QAbstractItemModel::index(int row, int column, const QModelIndex &parent) const.

rowcolumn 에 있는 데이터의 색인을 parent 로 반환합니다.

parent()도 참조하세요 .

[override virtual] QModelIndex QAbstractListModel::sibling(int row, int column, const QModelIndex &idx) const

재구현합니다: QAbstractItemModel::sibling(int row, int column, const QModelIndex &index) const.

© 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.