ItemSelectionModel QML Type

实例化QItemSelectionModel ,与QAbstractItemModel 和支持该 的任何视图结合使用。更多

Import Statement: import QtQml.Models
In C++: QItemSelectionModel

属性

信号

方法

详细说明

另请参阅 QItemSelectionModel 以及 Qt Quick 中的模型和视图

属性文档

currentIndex : QModelIndex [read-only]

使用setCurrentIndex() 设置属性值。

另请参阅 setCurrentIndex() 和currentChanged()。


hasSelection : bool [read-only]

每次发出selectionChanged() 时,即使其值未变,也会触发属性绑定更新。

另请参阅 selection,selectedIndexes,select() 和selectionChanged()。


model : QAbstractItemModel

该属性的值必须与视图的模型相匹配。


selectedIndexes : list<var> [read-only]

包含选择模型中所有索引(QModelIndex 实例)的列表。

另请参阅 QModelIndexList 类型


selection : object [read-only]

包含存储在选择模型中的选择范围。


信号文档

currentChanged(QModelIndex current, QModelIndex previous)

每当当前项目发生变化时,就会发出该信号。previous 模型项索引会被current 索引取代,成为选区的当前项。

请注意,重置项目模型时不会发出此信号。

注: 相应的处理程序是onCurrentChanged

另请参阅 currentIndex,setCurrentIndex() 和selectionChanged() 。


selectionChanged(QItemSelection selected, QItemSelection deselected)

每当选择项发生变化时,都会发出该信号。选中项的变化表现为deselected 项的选中项和selected 项的选中项。

请注意,当前索引的变化与选区无关。还要注意的是,重置项目模型时不会发出该信号。

注: 相应的处理程序是onSelectionChanged

另请参阅 select() 和currentChanged()。


方法文档

void clear()

清除选择模型。发出selectionChanged() 和currentChanged() 信号。


void clearCurrentIndex()

清除当前索引。发出currentChanged().


void clearSelection()

清除选择模型中的选择。发出selectionChanged() 信号。


bool columnIntersectsSelection(int column, QModelIndex parent)

如果column 中有任何项目被选中,给定的parent 将返回true


bool isColumnSelected(int column, QModelIndex parent)

如果在column 中选择了所有项目,则返回true ,给定parent

请注意,该函数通常比在同一列中的所有项目上调用isSelected() 更快,而且未被选中的项目会被忽略。


bool isRowSelected(int row, QModelIndex parent)

如果row 中的所有项目都被选中,则返回true ,给定parent

请注意,该函数通常比在同一行的所有项目上调用isSelected() 更快,而且会忽略不可选项目。


bool isSelected(QModelIndex index)

如果给定的模型项index 被选中,则返回true


void reset()

清除选择模型。不会发出任何信号。


bool rowIntersectsSelection(int row, QModelIndex parent)

如果row 中有任何项目被选中,给定的parent 将返回true


void select(QItemSelection selection, SelectionFlags command)

使用指定的command 选择项目selection ,并发出selectionChanged() 信号。

command 的有效值在 select(index, command).


void select(QModelIndex index, SelectionFlags command)

使用指定的command 选择模型项index ,并发送selectionChanged() 。

command 参数的有效值为 :

常量说明
NoUpdate不进行选择。
Clear将清除全部选择。
Select将选择所有指定的索引。
Deselect取消选择所有指定索引。
Toggle根据当前状态选择或取消选择所有指定的索引。
Current当前选择将被更新。
Rows所有索引都将扩展到跨行。
Columns所有索引都将扩展到跨列。
SelectCurrent选择 "和 "当前 "的组合,方便使用。
ToggleCurrent切换和当前的组合,提供方便。
ClearAndSelect清除和选择的组合,以方便使用。

list<var> selectedColumns(int row)

返回row 中所有行都被选中的列的索引(QModelIndex 实例列表)。

另请参阅 selectedRows() 和QModelIndexList 类型


list<var> selectedRows(int column)

返回给定column 中所有列都被选中的行的索引(一个QModelIndex 实例列表)。

另请参阅 selectedColumns() 和QModelIndexList 类型


void setCurrentIndex(QModelIndex index, SelectionFlags command)

将模型项index 设置为当前项,并发出currentChanged() 命令。当前项用于键盘导航和焦点指示;它与任何选中项无关,尽管选中项也可以是当前项。

根据指定的commandindex 也可以成为当前选中项的一部分。

command 的有效值在 select(index, command).

另请参阅 select() 。


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