QStringListModel Class
QStringListModel 클래스는 뷰에 문자열을 제공하는 모델을 제공합니다. 더 보기...
Header: | #include <QStringListModel> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
상속합니다: | QAbstractListModel |
상속 대상: |
공용 함수
QStringListModel(QObject *parent = nullptr) | |
QStringListModel(const QStringList &strings, QObject *parent = nullptr) | |
void | setStringList(const QStringList &strings) |
QStringList | stringList() const |
재구현된 공용 함수
(since 6.0) virtual bool | clearItemData(const QModelIndex &index) override |
virtual QVariant | data(const QModelIndex &index, int role = Qt::DisplayRole) const override |
virtual Qt::ItemFlags | flags(const QModelIndex &index) const override |
virtual bool | insertRows(int row, int count, const QModelIndex &parent = QModelIndex()) override |
virtual QMap<int, QVariant> | itemData(const QModelIndex &index) const override |
virtual bool | moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild) override |
virtual bool | removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override |
virtual int | rowCount(const QModelIndex &parent = QModelIndex()) const override |
virtual bool | setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override |
virtual bool | setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles) override |
virtual QModelIndex | sibling(int row, int column, const QModelIndex &idx) const override |
virtual void | sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override |
virtual Qt::DropActions | supportedDropActions() const override |
상세 설명
QStringListModel은 QListView 또는 QComboBox 과 같이 뷰 위젯에 여러 문자열을 표시해야 하는 간단한 경우에 사용할 수 있는 편집 가능한 모델입니다.
이 모델은 편집 가능한 모델의 모든 표준 함수를 제공하며, 문자열 목록의 데이터를 하나의 열과 목록의 항목 수와 동일한 수의 행을 가진 모델로 표현합니다.
항목에 해당하는 모델 인덱스는 index() 함수를 사용하여 얻고, 항목 플래그는 flags() 함수를 사용하여 얻습니다. 항목 데이터는 data() 함수로 읽고 setData() 함수로 씁니다. 행 수(및 문자열 목록의 항목 수)는 rowCount() 함수를 사용하여 찾을 수 있습니다.
기존 문자열 목록으로 모델을 구성하거나 setStringList() 편의 함수를 사용하여 나중에 문자열을 설정할 수 있습니다. 또한 insertRows() 함수를 사용하여 일반적인 방법으로 문자열을 삽입하고 removeRows() 함수를 사용하여 제거할 수도 있습니다. 문자열 목록의 내용은 stringList() 편의 함수를 사용하여 검색할 수 있습니다.
QStringListModel의 사용 예제:
QStringListModel *model = new QStringListModel(); QStringList list; list << "a" << "b" << "c"; model->setStringList(list);
QAbstractListModel, QAbstractItemModel, 및 Model 클래스를참조하십시오 .
멤버 함수 문서
[explicit]
QStringListModel::QStringListModel(QObject *parent = nullptr)
주어진 parent 으로 문자열 목록 모델을 구축합니다.
[explicit]
QStringListModel::QStringListModel(const QStringList &strings, QObject *parent = nullptr)
지정된 parent 을 사용하여 지정된 strings 을 포함하는 문자열 목록 모델을 구축합니다.
[override virtual, since 6.0]
bool QStringListModel::clearItemData(const QModelIndex &index)
재구현합니다: QAbstractItemModel::clearItemData(const QModelIndex &index).
이 함수는 Qt 6.0에 도입되었습니다.
[override virtual]
QVariant QStringListModel::data(const QModelIndex &index, int role = Qt::DisplayRole) const
재구현합니다: QAbstractItemModel::data(const QModelIndex &index, int role) const.
지정된 index 이 있는 항목에서 지정된 role 에 대한 데이터를 반환합니다.
뷰가 잘못된 인덱스를 요청하면 잘못된 변형이 반환됩니다.
setData()도 참조하세요 .
[override virtual]
Qt::ItemFlags QStringListModel::flags(const QModelIndex &index) const
재구현합니다: QAbstractListModel::flags(const QModelIndex &index) const.
주어진 index 을 가진 항목의 플래그를 반환합니다.
유효한 항목은 활성화, 선택 가능, 편집 가능, 드래그 가능 및 드롭 가능입니다.
QAbstractItemModel::flags()도 참조하세요 .
[override virtual]
bool QStringListModel::insertRows(int row, int count, const QModelIndex &parent = QModelIndex())
재구현합니다: QAbstractItemModel::insertRows(int row, int count, const QModelIndex &parent).
주어진 row 에서 시작하여 count 행을 모델에 삽입합니다.
행의 parent 인덱스는 선택 사항이며 QAbstractItemModel 과의 일관성을 위해서만 사용됩니다. 기본적으로 모델의 최상위 레벨에 행이 삽입됨을 나타내는 null 인덱스가 지정됩니다.
삽입에 성공하면 true
을 반환합니다.
QAbstractItemModel::insertRows()도 참조하세요 .
[override virtual]
QMap<int, QVariant> QStringListModel::itemData(const QModelIndex &index) const
재구현합니다: QAbstractItemModel::itemData(const QModelIndex &index) const.
setItemData()도 참조하십시오 .
[override virtual]
bool QStringListModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)
재구현합니다: QAbstractItemModel::moveRows(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild).
[override virtual]
bool QStringListModel::removeRows(int row, int count, const QModelIndex &parent = QModelIndex())
재구현합니다: QAbstractItemModel::removeRows(int row, int count, const QModelIndex &parent).
주어진 row 에서 시작하여 모델에서 count 행을 제거합니다.
행의 parent 인덱스는 선택 사항이며 QAbstractItemModel 과의 일관성을 위해서만 사용됩니다. 기본적으로 모델의 최상위 수준에서 행이 제거됨을 나타내는 null 인덱스가 지정됩니다.
행 제거에 성공하면 true
을 반환합니다.
QAbstractItemModel::removeRows()도 참조하세요 .
[override virtual]
int QStringListModel::rowCount(const QModelIndex &parent = QModelIndex()) const
재구현합니다: QAbstractItemModel::rowCount(const QModelIndex &parent) const.
모델의 행 수를 반환합니다. 이 값은 모델의 내부 문자열 목록에 있는 항목 수에 해당합니다.
선택적 parent 인수는 대부분의 모델에서 카운트할 행의 부모를 지정하는 데 사용됩니다. 유효한 부모가 지정되면 목록이므로 결과는 항상 0이 됩니다.
insertRows(), removeRows() 및 QAbstractItemModel::rowCount()도 참조하세요 .
[override virtual]
bool QStringListModel::setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole)
재구현합니다: QAbstractItemModel::setData(const QModelIndex &index, const QVariant &value, int role).
모델에 지정된 index 이 있는 항목에서 지정된 role 의 데이터를 지정된 value 로 설정합니다.
항목이 변경되면 dataChanged() 신호가 발생합니다. dataChanged () 신호를 보낸 후 true
를 반환합니다.
Qt::ItemDataRole 및 data()도 참조하세요 .
[override virtual]
bool QStringListModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles)
재구현합니다: QAbstractItemModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles).
roles 에 Qt::DisplayRole 과 Qt::EditRole 이 모두 포함된 경우 후자가 우선합니다.
itemData()도 참조하세요 .
void QStringListModel::setStringList(const QStringList &strings)
모델의 내부 문자열 목록을 strings 로 설정합니다. 모델은 연결된 모든 뷰에 기초 데이터가 변경되었음을 알립니다.
stringList() 및 dataChanged()도 참조하세요 .
[override virtual]
QModelIndex QStringListModel::sibling(int row, int column, const QModelIndex &idx) const
재구현합니다: QAbstractListModel::sibling(int row, int column, const QModelIndex &idx) const.
[override virtual]
void QStringListModel::sort(int column, Qt::SortOrder order = Qt::AscendingOrder)
재구현합니다: QAbstractItemModel::sort(int column, Qt::SortOrder 순서).
QStringList QStringListModel::stringList() const
모델에서 데이터를 저장하는 데 사용하는 문자열 목록을 반환합니다.
setStringList()도 참조하세요 .
[override virtual]
Qt::DropActions QStringListModel::supportedDropActions() const
재구현합니다: QAbstractItemModel::supportedDropActions() 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.