模型视图(20):【类】QItemSelectionModel[官翻]

QItemSelectionModel 类

QItemSelectionModel类跟踪视图的选中项。

Header:#include < QItemSelectionModel>
qmake:QT += core
Inherits:QObject
Inherited By:

详述

QItemSelectionModel跟踪一个视图或同一模型的多个视图中选定的项目。它跟踪视图中当前选定的项。

QItemSelectionModel类是一个模型/视图类,是Qt模型/视图框架的一部分。

使用范围存储所选项。每当你想要修改选中的项目时,使用select()并提供QItemSelection,或者QModelIndex和QItemSelectionModel::SelectionFlag。

QItemSelectionModel采用两层方法进行选择管理,既处理已提交的选定项,也处理作为当前选择的一部分的选定项。当前选中的项目是当前交互选择的一部分(例如,使用橡皮带选择或键盘shift选择)。

要更新当前选中的项目,使用QItemSelectionModel::Current的位OR和其他任何SelectionFlags。如果省略QItemSelectionModel::Current命令,将创建一个新的当前选择,之前的选择将添加到整个选择中。所有的功能都在这两层上操作;例如,selecteditems()将返回来自两个层的项目。

注意:从5.5开始,model、hasSelection和currentIndex都是元对象属性。

公共类型

enum SelectionFlag

flags SelectionFlags

这个枚举描述了更新选择模型的方式。

ConstantValueDescription
NoUpdate0x0000不进行任何选择。
Clear0x0001完整的选择将被清除。
Select0x0002将选择所有指定的索引。
Deselect0x0004所有指定的索引将被取消。
Toggle0x0008所有指定的索引将根据其当前状态被选中或取消选中。
Current0x0010当前的选择将被更新。
Rows0x0020所有索引都将扩展为跨行。
Columns0x0040所有索引都将扩展为跨列。
SelectCurrentSelect | Current选择和当前的组合,提供了方便。
ToggleCurrentToggle | Current一种切换和当前的组合,提供了方便。
ClearAndSelectClear | Select明确和选择的结合,提供了方便。

属性

  • selectedIndexes : const QModelIndexList
    QModelIndexList selectedIndexes() const

公共函数

构造析构

  1. QItemSelectionModel(QAbstractItemModel *model, QObject *parent)
  2. QItemSelectionModel(QAbstractItemModel *model = nullptr)
  3. virtual ~QItemSelectionModel()

交互

  1. bool columnIntersectsSelection(int column, const QModelIndex &parent = QModelIndex()) const
    是否在具有给定父节点的列中有选定项
    注意:从Qt 5.15开始,parent的默认参数是一个空的模型索引。
    注意:这个函数可以通过元对象系统调用,也可以从QML调用。看到Q_INVOKABLE。
  2. bool rowIntersectsSelection(int row, const QModelIndex &parent = QModelIndex()) const
    是否在具有给定父节点的行中有选定项

模型和索引

  1. const QAbstractItemModel * model() const
  2. QAbstractItemModel * model()
  3. void setModel(QAbstractItemModel *model)
  4. QModelIndex currentIndex() const

选定

  1. bool hasSelection() const 是否有选择范围
  2. const QItemSelection selection() const 返回存储在选择模型中的选择范围
  3. bool isColumnSelected(int column, const QModelIndex &parent = QModelIndex()) const
    是否在具有给定父元素的列中选择了所有项
    请注意,这个函数通常比对同一列中的所有项调用isSelected()要快,而且不可选择的项将被忽略。
    注意:从Qt 5.15开始,parent的默认参数是一个空的模型索引。
  4. bool isRowSelected(int row, const QModelIndex &parent = QModelIndex()) const
    是否在具有给定父元素的行中选择了所有项
  5. bool isSelected(const QModelIndex &index) const 是否在给定的索引被选定
  6. QModelIndexList selectedColumns(int row = 0) const
    返回给定行中所有行都已选中的列的索引
  7. QModelIndexList selectedRows(int column = 0) const
    返回给定列中所有行都已选中的行的索引
  8. QModelIndexList selectedIndexes() const
    返回所有选中的模型项索引的列表。该列表不包含重复项,且未排序

公共槽

  1. virtual void clear()
  2. virtual void clearCurrentIndex()
  3. void clearSelection()
  4. virtual void reset()
  5. virtual void select(const QItemSelection &selection, QItemSelectionModel::SelectionFlags command)
  6. virtual void select(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)
  7. virtual void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command)

信号

  1. void currentChanged(const QModelIndex &current, const QModelIndex &previous)
  2. void currentColumnChanged(const QModelIndex &current, const QModelIndex &previous)
  3. void currentRowChanged(const QModelIndex &current, const QModelIndex &previous)
  4. void modelChanged(QAbstractItemModel *model)
  5. void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected)

受保护的函数

  1. void emitSelectionChanged(const QItemSelection &newSelection, const QItemSelection &oldSelection)

参见

  • 模型/视图编程
  • QAbstractItemModel
  • 图表示例
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值