QItemSelectionModel 类保持视图选中项的跟踪。 更多...
头: | #include <QItemSelectionModel> |
CMake: |
find_package(Qt6 COMPONENTS Core REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
继承: | QObject |
enum | SelectionFlag { NoUpdate, Clear, Select, Deselect, Toggle, …, ClearAndSelect } |
flags | SelectionFlags |
QItemSelectionModel (QAbstractItemModel * model , QObject * parent ) | |
QItemSelectionModel (QAbstractItemModel * model = nullptr) | |
virtual | ~QItemSelectionModel () |
bool | columnIntersectsSelection (int column , const QModelIndex & parent = QModelIndex()) const |
QModelIndex | currentIndex () const |
bool | hasSelection () const |
bool | isColumnSelected (int column , const QModelIndex & parent = QModelIndex()) const |
bool | isRowSelected (int row , const QModelIndex & parent = QModelIndex()) const |
bool | isSelected (const QModelIndex & index ) const |
const QAbstractItemModel * | model () const |
QAbstractItemModel * | model () |
bool | rowIntersectsSelection (int row , const QModelIndex & parent = QModelIndex()) const |
QModelIndexList | selectedColumns (int row = 0) const |
QModelIndexList | selectedIndexes () const |
QModelIndexList | selectedRows (int column = 0) const |
const QItemSelection | selection () const |
void | setModel (QAbstractItemModel * model ) |
virtual void | clear () |
virtual void | clearCurrentIndex () |
void | clearSelection () |
virtual void | reset () |
virtual void | select (const QItemSelection & selection , QItemSelectionModel::SelectionFlags 命令 ) |
virtual void | select (const QModelIndex & index , QItemSelectionModel::SelectionFlags 命令 ) |
virtual void | setCurrentIndex (const QModelIndex & index , QItemSelectionModel::SelectionFlags 命令 ) |
void | currentChanged (const QModelIndex & current , const QModelIndex & previous ) |
void | currentColumnChanged (const QModelIndex & current , const QModelIndex & previous ) |
void | currentRowChanged (const QModelIndex & current , const QModelIndex & previous ) |
void | modelChanged (QAbstractItemModel * model ) |
void | selectionChanged (const QItemSelection & selected , const QItemSelection & deselected ) |
void | emitSelectionChanged (const QItemSelection & newSelection , const QItemSelection & oldSelection ) |
QItemSelectionModel 保持对视图或同一模型多个视图中的选中项的跟踪。它还保持对视图中当前选中项的跟踪。
QItemSelectionModel 类是一种 模型/视图类 且属于 Qt 的 模型/视图框架 .
选中项使用范围存储。每当想要修改选中项时,使用 select () 和提供 QItemSelection ,或 QModelIndex 和 QItemSelectionModel::SelectionFlag .
QItemSelectionModel 采用 2 层方式进行选定管理,既处理已提交的选定项,也处理作为当前选定一部分的项。当前选中项是当前交互选定的一部分 (例如:采用橡皮筋选择或键盘 Shift 选择)。
要更新目前的选中项,使用按位 OR 的 QItemSelectionModel::Current 和任何其它 SelectionFlags 。若省略 QItemSelectionModel::Current 命令将创建新的当前选定,并将之前的添加到整个选定。所有函数运转于两者层;例如, selecteditems() 将从 2 层返回项。
注意: 从 5.5 起, model , hasSelection ,和 currentIndex 是元对象特性。
另请参阅 模型/视图编程 , QAbstractItemModel ,和 图表范例 .
此枚举描述将更新选定模型的方式。
常量 | 值 | 描述 |
---|---|---|
QItemSelectionModel::NoUpdate
|
0x0000
|
不会做出选择。 |
QItemSelectionModel::Clear
|
0x0001
|
完整选定将被清零。 |
QItemSelectionModel::Select
|
0x0002
|
所有指定索引将被选中。 |
QItemSelectionModel::Deselect
|
0x0004
|
所有指定索引将被取消选择。 |
QItemSelectionModel::Toggle
|
0x0008
|
所有指定索引将根据它们的当前状态被选中或取消选择。 |
QItemSelectionModel::Current
|
0x0010
|
当前选定将被更新。 |
QItemSelectionModel::Rows
|
0x0020
|
将扩展所有索引以跨行。 |
QItemSelectionModel::Columns
|
0x0040
|
将扩展所有索引以跨列。 |
QItemSelectionModel::SelectCurrent
|
Select | Current
|
Select 和 Current 的组合,为方便起见提供。 |
QItemSelectionModel::ToggleCurrent
|
Toggle | Current
|
Toggle 和 Current 的组合,为方便起见提供。 |
QItemSelectionModel::ClearAndSelect
|
Clear | Select
|
Clear 和 Select 的组合,为方便起见提供。 |
SelectionFlags 类型是 typedef 对于 QFlags <SelectionFlag>。它存储 SelectionFlag 值的 OR 组合。
[read-only, since 5.5]
selectedIndexes
: const
QModelIndexList
该特性在 Qt 5.5 引入。
访问函数:
QModelIndexList | selectedIndexes () const |
通知程序信号:
void | selectionChanged (const QItemSelection & selected , const QItemSelection & deselected ) |
Constructs a selection model that operates on the specified item model with parent .
Constructs a selection model that operates on the specified item model .
[virtual slot]
void
QItemSelectionModel::
clear
()
清零选定模型。发射 selectionChanged () 和 currentChanged ().
[virtual slot]
void
QItemSelectionModel::
clearCurrentIndex
()
清零当前索引。发射 currentChanged ().
[slot]
void
QItemSelectionModel::
clearSelection
()
Clears the selection in the selection model. Emits selectionChanged ().
[signal]
void
QItemSelectionModel::
currentChanged
(const
QModelIndex
&
current
, const
QModelIndex
&
previous
)
此信号被发射每当当前项改变。 previous model item index is replaced by the current index as the selection's current item.
Note that this signal will not be emitted when the item model is reset.
另请参阅 currentIndex (), setCurrentIndex (),和 selectionChanged ().
[signal]
void
QItemSelectionModel::
currentColumnChanged
(const
QModelIndex
&
current
, const
QModelIndex
&
previous
)
此信号被发射,若 current item changes and its column is different to the column of the previous 当前项。
Note that this signal will not be emitted when the item model is reset.
另请参阅 currentChanged (), currentRowChanged (), currentIndex (),和 setCurrentIndex ().
[signal]
void
QItemSelectionModel::
currentRowChanged
(const
QModelIndex
&
current
, const
QModelIndex
&
previous
)
此信号被发射,若 current item changes and its row is different to the row of the previous 当前项。
Note that this signal will not be emitted when the item model is reset.
另请参阅 currentChanged (), currentColumnChanged (), currentIndex (),和 setCurrentIndex ().
[signal, since 5.5]
void
QItemSelectionModel::
modelChanged
(
QAbstractItemModel
*
model
)
此信号被发射当 model is successfully set with setModel ().
该函数在 Qt 5.5 引入。
[virtual slot]
void
QItemSelectionModel::
reset
()
Clears the selection model. Does not emit any signals.
[virtual slot]
void
QItemSelectionModel::
select
(const
QItemSelection
&
selection
,
QItemSelectionModel::SelectionFlags
命令
)
选择项 selection 使用指定 命令 ,和发射 selectionChanged ().
另请参阅 QItemSelectionModel::SelectionFlag .
[virtual slot]
void
QItemSelectionModel::
select
(const
QModelIndex
&
index
,
QItemSelectionModel::SelectionFlags
命令
)
选择模型项 index 使用指定 命令 ,和发射 selectionChanged ().
另请参阅 QItemSelectionModel::SelectionFlags .
[signal]
void
QItemSelectionModel::
selectionChanged
(const
QItemSelection
&
selected
, const
QItemSelection
&
deselected
)
This signal is emitted whenever the selection changes. The change in the selection is represented as an item selection of deselected items and an item selection of selected 项。
Note the that the current index changes independently from the selection. Also note that this signal will not be emitted when the item model is reset.
Items which stay selected but change their index are not included in selected and deselected . Thus, this signal might be emitted with both selected and deselected empty, if only the indices of selected items change.
注意: 通知程序信号对于特性 selectedIndexes .
另请参阅 select () 和 currentChanged ().
[virtual slot]
void
QItemSelectionModel::
setCurrentIndex
(const
QModelIndex
&
index
,
QItemSelectionModel::SelectionFlags
命令
)
Sets the model item index to be the current item, and emits currentChanged (). The current item is used for keyboard navigation and focus indication; it is independent of any selected items, although a selected item can also be the current item.
从属指定 命令 , index 也可以变为当前选定的一部分。
另请参阅 currentIndex () 和 select ().
[虚拟]
QItemSelectionModel::
~QItemSelectionModel
()
销毁选定模型。
[invokable]
bool
QItemSelectionModel::
columnIntersectsSelection
(
int
column
, const
QModelIndex
&
parent
= QModelIndex()) const
返回
true
若有选中任何项在
column
采用给定
parent
.
注意: 从 Qt 5.15 起,默认自变量对于 parent 是空模型索引。
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
Returns the model item index for the current item, or an invalid index if there is no current item.
另请参阅 setCurrentIndex ().
[protected]
void
QItemSelectionModel::
emitSelectionChanged
(const
QItemSelection
&
newSelection
, const
QItemSelection
&
oldSelection
)
比较 2 选定 newSelection and oldSelection 并发射 selectionChanged () with the deselected and selected items.
返回
true
if the selection model contains any selected item, otherwise returns
false
.
[invokable]
bool
QItemSelectionModel::
isColumnSelected
(
int
column
, const
QModelIndex
&
parent
= QModelIndex()) const
返回
true
if all items are selected in the
column
采用给定
parent
.
Note that this function is usually faster than calling isSelected () on all items in the same column and that unselectable items are ignored.
注意: 从 Qt 5.15 起,默认自变量对于 parent 是空模型索引。
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
[invokable]
bool
QItemSelectionModel::
isRowSelected
(
int
row
, const
QModelIndex
&
parent
= QModelIndex()) const
返回
true
if all items are selected in the
row
采用给定
parent
.
Note that this function is usually faster than calling isSelected () on all items in the same row and that unselectable items are ignored.
注意: 从 Qt 5.15 起,默认自变量对于 parent 是空模型索引。
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
[invokable]
bool
QItemSelectionModel::
isSelected
(const
QModelIndex
&
index
) const
返回
true
若给定模型项
index
被选中。
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
返回由选定模型操作的项模型。
另请参阅 setModel ().
[since 5.5]
QAbstractItemModel
*QItemSelectionModel::
model
()
返回由选定模型操作的项模型。
该函数在 Qt 5.5 引入。
[invokable]
bool
QItemSelectionModel::
rowIntersectsSelection
(
int
row
, const
QModelIndex
&
parent
= QModelIndex()) const
返回
true
若有选中任何项在
row
采用给定
parent
.
注意: 从 Qt 5.15 起,默认自变量对于 parent 是空模型索引。
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
[invokable]
QModelIndexList
QItemSelectionModel::
selectedColumns
(
int
row
= 0) const
返回的索引在给定 row 对于选中所有行的列而言。
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
另请参阅 selectedIndexes () 和 selectedRows ().
返回所有选中模型项索引的列表。列表包含的不重复,且未排序。
注意: getter 函数对于特性 selectedIndexes。
[invokable]
QModelIndexList
QItemSelectionModel::
selectedRows
(
int
column
= 0) const
返回的索引在给定 column 对于选中所有列的行而言。
注意: 此函数可以被援引,通过元对象系统和从 QML。见 Q_INVOKABLE .
另请参阅 selectedIndexes () 和 selectedColumns ().
返回存储在选定模型中的选定范围。
[since 5.5]
void
QItemSelectionModel::
setModel
(
QAbstractItemModel
*
model
)
将模型设为 model 。 modelChanged () 信号会被发射。
该函数在 Qt 5.5 引入。
另请参阅 model () 和 modelChanged ().