QStringListModel Class

QStringListModel クラスは、ビューに文字列を供給するモデルを提供します。詳細...

ヘッダー #include <QStringListModel>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
を継承する: QAbstractListModel
継承元:

QHelpIndexModel

パブリック関数

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 は編集可能なモデルで、QListViewQComboBox のようなビューウィジェットで、いくつかの文字列を表示する必要がある場合に使用することができます。

このモデルは、編集可能なモデルの標準的な機能をすべて提供し、文字列リストのデータを、リスト内のアイテムの数と同じ数の1つの列と行を持つモデルとして表現します。

項目に対応するモデル・インデックスは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,モデル・クラスも参照してください

メンバ関数のドキュメント

[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 のアイテムのフラグを返します。

有効な項目は、enabled、selectable、editable、drag enabled、drop enabled です。

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)。

rolesQt::DisplayRoleQt::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 order).

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.