本页内容

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 中所有项目都符合给定的parent ,则返回true 。

请注意,此函数通常比对同一列中的所有项目分别调用isSelected() 更快,且不可选的项目将被忽略。

bool isRowSelected(int row, QModelIndex parent)

如果row 中所有项目均被选中(且parent 为指定值),则返回true 。

请注意,此函数通常比对同一行中的所有项目调用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()事件。当前项用于键盘导航和焦点指示;它与任何选中项无关,尽管选中项也可以是当前项。

根据指定的command ,index 也可能成为当前选区的一部分。

有效的command 值在 select(index, command)中所述。

另请参阅 select()。

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