PySide6.QtCore.QItemSelection

class QItemSelection

QItemSelection 类管理模型中选定项目的信息。更多

概要

方法

静态函数

注意

本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。

详细描述

警告

本节包含从C++自动翻译到Python的代码片段,可能包含错误。

一个QItemSelection描述了用户选择的模型中的项目。QItemSelection基本上是一个选择范围的列表,参见QItemSelectionRange。它提供了创建和操作选择以及从模型中选择一系列项目的函数。

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

可以构建并初始化一个项目选择,以包含来自现有模型的一系列项目。以下示例构建了一个选择,该选择包含来自给定model的一系列项目,从topLeft开始,到bottomRight结束。

selection = QItemSelection(topLeft, bottomRight)

可以构造一个空的项目选择,然后根据需要填充。因此,如果在我们构造项目选择时模型不可用,我们可以用以下方式重写上述代码:

selection = QItemSelection()
...
selection.select(topLeft, bottomRight)

QItemSelection 通过使用选择范围而不是记录选择中每个项目的模型项目索引来节省内存,并避免不必要的工作。通常,此类的实例将包含一个不重叠的选择范围列表。

使用merge()将一个项目选择合并到另一个项目中,而不会产生重叠范围。使用split()根据另一个选择范围将一个选择范围拆分为更小的范围。

另请参阅

QItemSelectionModel

__init__()

构造一个空的选择。

__init__(topLeft, bottomRight)
Parameters:

构造一个项目选择,从左上角的模型项目(由topLeft索引指定)延伸到右下角的项目(由bottomRight指定)。

append(arg__1)
Parameters:

arg__1QItemSelectionRange

append(l)
Parameters:

l – QItemSelectionRange 的列表

at(i)
Parameters:

i – 整数

Return type:

QItemSelectionRange

back()
Return type:

QItemSelectionRange

capacity()
Return type:

整数

clear()
constData()
Return type:

QItemSelectionRange

constFirst()
Return type:

QItemSelectionRange

constLast()
Return type:

QItemSelectionRange

contains(index)
Parameters:

索引QModelIndex

Return type:

布尔

如果选择包含给定的index,则返回true;否则返回false

count()
Return type:

整数

data()
Return type:

QItemSelectionRange

empty()
Return type:

布尔

first()
Return type:

QItemSelectionRange

first(n)
Parameters:

n – 整数

Return type:

QItemSelectionRange 的列表

static fromList(list)
Parameters:

列表 – QItemSelectionRange 的列表

Return type:

.list of QItemSelectionRange

static fromVector(vector)
Parameters:

vector – QItemSelectionRange 的列表

Return type:

QItemSelectionRange的列表

front()
Return type:

QItemSelectionRange

indexes()
Return type:

QModelIndex 的列表

返回与所选项目对应的模型索引列表。

insert(arg__1, arg__2)
Parameters:
isEmpty()
Return type:

布尔

isSharedWith(other)
Parameters:

其他 – .QItemSelectionRange 的列表

Return type:

布尔

last()
Return type:

QItemSelectionRange

last(n)
Parameters:

n – 整数

Return type:

.list of QItemSelectionRange

length()
Return type:

整数

static maxSize()
Return type:

整数

max_size()
Return type:

整数

merge(other, command)
Parameters:

使用给定的commandother选择与这个QItemSelection合并。此方法确保没有范围重叠。

请注意,仅支持SelectDeselectToggle

另请参阅

split()

mid(pos[, len=-1])
Parameters:
  • pos – 整数

  • len – int

Return type:

QItemSelectionRange的列表

move(from, to)
Parameters:
  • from – 整数

  • to – int

__ne__(arg__1)
Parameters:

arg__1QItemSelection

Return type:

布尔

__add__(arg__1)
Parameters:

arg__1QItemSelection

Return type:

QItemSelection

__iadd__(l)
Parameters:

l – QItemSelectionRange 的列表

Return type:

QItemSelectionRange的列表

__lshift__(l)
Parameters:

l – QItemSelectionRange 的列表

Return type:

QItemSelectionRange的列表

__eq__(arg__1)
Parameters:

arg__1QItemSelection

Return type:

布尔

operator(i)
Parameters:

i – 整数

Return type:

QItemSelectionRange

pop_back()
pop_front()
prepend(arg__1)
Parameters:

arg__1QItemSelectionRange

push_back(arg__1)
Parameters:

arg__1QItemSelectionRange

push_front(arg__1)
Parameters:

arg__1QItemSelectionRange

remove(i[, n=1])
Parameters:
  • i – 整数

  • n – 整数

removeAll(arg__1)
Parameters:

arg__1QItemSelectionRange

removeAt(i)
Parameters:

i – 整数

removeFirst()
removeLast()
removeOne(arg__1)
Parameters:

arg__1QItemSelectionRange

reserve(size)
Parameters:

size – int

resize(size)
Parameters:

size – int

resizeForOverwrite(size)
Parameters:

size – int

select(topLeft, bottomRight)
Parameters:

将范围中的项目添加到列表中,该范围从左上角的模型项目(由topLeft索引指定)延伸到右下角的项目(由bottomRight指定)。

注意

topLeftbottomRight 必须具有相同的父级。

shrink_to_fit()
size()
Return type:

整数

sliced(pos)
Parameters:

pos – 整数

Return type:

QItemSelectionRange的列表

sliced(pos, n)
Parameters:
  • pos – 整数

  • n – 整数

Return type:

QItemSelectionRange的列表

static split(range, other, result)
Parameters:

使用选择范围 other 来分割选择范围 range。从 range 中移除所有在 other 中的项,并将结果放入 result。这可以与集合的减法操作的语义进行比较。

另请参阅

merge()

squeeze()
swap(other)
Parameters:

其他 – .QItemSelectionRange 的列表

swapItemsAt(i, j)
Parameters:
  • i – 整数

  • j – int

takeAt(i)
Parameters:

i – 整数

Return type:

QItemSelectionRange

toList()
Return type:

QItemSelectionRange的列表

toVector()
Return type:

QItemSelectionRange的列表

value(i)
Parameters:

i – 整数

Return type:

QItemSelectionRange