このページでは

QItemSelection Class

QItemSelection クラスは、モデル内で選択された項目に関する情報を管理します。詳細...

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

パブリック関数

QItemSelection()
QItemSelection(const QModelIndex &topLeft, const QModelIndex &bottomRight)
bool contains(const QModelIndex &index) const
QModelIndexList indexes() const
void merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command)
void select(const QModelIndex &topLeft, const QModelIndex &bottomRight)

静的パブリックメンバー

void split(const QItemSelectionRange &range, const QItemSelectionRange &other, QItemSelection *result)

詳細な説明

QItemSelection は、ユーザーによって選択されたモデル内の項目を表します。QItemSelection は基本的に選択範囲のリストであり、QItemSelectionRange を参照してください。このクラスは、選択の作成や操作、およびモデルからの項目の範囲の選択を行うための関数を提供します。

QItemSelection クラスはModel/View クラスの一つであり、Qtのモデル/ビューフレームワークの一部です。

アイテム選択は、既存のモデルからアイテムの範囲を含むように構築および初期化できます。次の例では、指定されたmodel から、topLeft を起点とし、bottomRight を終点とするアイテムの範囲を含む選択を構築しています。

QItemSelection *selection = new QItemSelection(topLeft, bottomRight);

空のアイテム選択を構築し、後で必要に応じてデータを格納することもできます。したがって、アイテム選択を構築する時点でモデルが利用できない場合は、上記のコードを次のように書き換えることができます。

QItemSelection *selection = new QItemSelection();
//...
selection->select(topLeft, bottomRight);

QItemSelectionは、選択内の各アイテムのモデルアイテムインデックスを記録するのではなく、選択範囲を扱うことで、メモリを節約し、不要な処理を回避します。一般的に、このクラスのインスタンスには、重複しない選択範囲のリストが含まれます。

merge() を使用すると、範囲が重複することなく、あるアイテム選択を別のアイテム選択にマージできます。split() を使用すると、別の選択範囲に基づいて、ある選択範囲をより小さな範囲に分割できます。

「モデル/ビュープログラミング」および「QItemSelectionModel 」も参照してください 。

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

[implicit] QItemSelection::QItemSelection()

空の選択範囲を作成します。

QItemSelection::QItemSelection(const QModelIndex &topLeft, const QModelIndex &bottomRight)

topLeft インデックスで指定された左上のモデルアイテムから、bottomRight で指定された右下のアイテムまで広がるアイテム選択範囲を作成します。

bool QItemSelection::contains(const QModelIndex &index) const

選択範囲に指定されたindex が含まれている場合はtrue を返し、含まれていない場合はfalse を返します。

QModelIndexList QItemSelection::indexes() const

選択された項目に対応するモデルインデックスのリストを返します。

void QItemSelection::merge(const QItemSelection &other, QItemSelectionModel::SelectionFlags command)

指定されたcommand を使用して、other の選択範囲とこのQItemSelection をマージします。この方法では、範囲の重複がないことが保証されます。

なお、サポートされているのは `QItemSelectionModel::Select`、`QItemSelectionModel::Deselect`、および `QItemSelectionModel::Toggle ` のみであることに注意してください。

split()も参照してください 。

void QItemSelection::select(const QModelIndex &topLeft, const QModelIndex &bottomRight)

topLeft で指定された左上のモデル項目から、bottomRight で指定された右下の項目に至る範囲内の項目を、リストに追加します。

注: topLeft とbottomRight は、同じ親を持つ必要があります。

[static] void QItemSelection::split(const QItemSelectionRange &range, const QItemSelectionRange &other, QItemSelection *result)

選択範囲range を、選択範囲other の範囲を用いて分割します。other 内のすべての項目をrange から削除し、その結果をresult に格納します。これは、集合の「引き算」演算の意味論と比較することができます。

merge()も参照してください 。

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