QItemSelectionRange Class

QItemSelectionRange 类管理有关模型中选定项范围的信息。更多

Header: #include <QItemSelectionRange>
CMake.QItemSelectionRange 类 find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

该类具有等价可比性

公共函数

QItemSelectionRange()
QItemSelectionRange(const QModelIndex &index)
QItemSelectionRange(const QModelIndex &topLeft, const QModelIndex &bottomRight)
int bottom() const
const QPersistentModelIndex &bottomRight() const
bool contains(const QModelIndex &index) const
bool contains(int row, int column, const QModelIndex &parentIndex) const
int height() const
QModelIndexList indexes() const
QItemSelectionRange intersected(const QItemSelectionRange &other) const
bool intersects(const QItemSelectionRange &other) const
bool isEmpty() const
bool isValid() const
int left() const
const QAbstractItemModel *model() const
QModelIndex parent() const
int right() const
void swap(QItemSelectionRange &other)
int top() const
const QPersistentModelIndex &topLeft() const
int width() const
bool operator!=(const QItemSelectionRange &lhs, const QItemSelectionRange &rhs)
bool operator==(const QItemSelectionRange &lhs, const QItemSelectionRange &rhs)

详细描述

QItemSelectionRange 包含模型中选定项范围的信息。项目范围是模型项目的连续数组,扩展至覆盖具有共同父项目的若干相邻行和列;这可以可视化为表格中的二维单元格块。一个选择范围有top(),left(),bottom(),right() 和parent().

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

可使用indexes() 函数获取选择范围中包含的模型项。使用QItemSelectionModel::selectedIndexes() 可获取视图的所有选中项的列表。

使用contains() 函数可以确定给定的模型项是否位于特定范围内。还可以使用重载的相等和不等式操作符比较范围,使用intersects() 函数可以确定两个范围是否重叠。

另请参阅 模型/视图编程QAbstractItemModelQItemSelectionQItemSelectionModel

成员函数文档

[noexcept] QItemSelectionRange::QItemSelectionRange()

构造一个空的选择范围。

[explicit] QItemSelectionRange::QItemSelectionRange(const QModelIndex &index)

构建一个新的选择范围,其中只包含由模型索引index 指定的模型项。

QItemSelectionRange::QItemSelectionRange(const QModelIndex &topLeft, const QModelIndex &bottomRight)

构建一个新的选择范围,其中只包含topLeft 和索引bottomRight 指定的索引。

int QItemSelectionRange::bottom() const

返回与选择范围中最下层所选行相对应的行索引。

const QPersistentModelIndex &QItemSelectionRange::bottomRight() const

返回位于选择范围右下角的项目索引。

另请参阅 bottom()、right() 和topLeft()。

bool QItemSelectionRange::contains(const QModelIndex &index) const

如果index 所指定的模型项在所选项的范围内,则返回true ;否则返回false

bool QItemSelectionRange::contains(int row, int column, const QModelIndex &parentIndex) const

这是一个重载函数。

如果 (row,column) 指定的、以parentIndex 为父项目的模型项目在所选项的范围内,则返回true ;否则返回false

int QItemSelectionRange::height() const

返回选择范围内的选定行数。

QModelIndexList QItemSelectionRange::indexes() const

返回存储在选择项中的模型索引项列表。

QItemSelectionRange QItemSelectionRange::intersected(const QItemSelectionRange &other) const

返回一个新的选择范围,其中只包含在选择范围和other 选择范围中都能找到的项目。

bool QItemSelectionRange::intersects(const QItemSelectionRange &other) const

如果该选择范围与所给的other 范围相交(重叠),则返回true ;否则返回false

bool QItemSelectionRange::isEmpty() const

如果选择范围不包含项目或仅包含禁用或标记为不可选的项目,则返回true

bool QItemSelectionRange::isValid() const

如果选择范围有效,则返回true ;否则返回false

int QItemSelectionRange::left() const

返回与选择范围中最左侧所选列相对应的列索引。

const QAbstractItemModel *QItemSelectionRange::model() const

返回选择范围内的项目所属的模型。

QModelIndex QItemSelectionRange::parent() const

返回选择范围内项目的父模型项目索引。

返回与选择范围中最右侧所选列相对应的列索引。

[noexcept] void QItemSelectionRange::swap(QItemSelectionRange &other)

将该选择范围的内容与other 互换。该操作速度非常快,而且从未出现过故障。

int QItemSelectionRange::top() const

返回与选择范围中最上选中行相对应的行索引。

const QPersistentModelIndex &QItemSelectionRange::topLeft() const

返回位于选择范围左上角的项目索引。

另请参阅 top()、left() 和bottomRight()。

int QItemSelectionRange::width() const

返回选择范围内所选列的数量。

相关非成员

[noexcept] bool operator!=(const QItemSelectionRange &lhs, const QItemSelectionRange &rhs)

如果lhs 的选择范围与rhs 的选择范围不同,则返回true ;否则返回false

[noexcept] bool operator==(const QItemSelectionRange &lhs, const QItemSelectionRange &rhs)

如果lhs 的选择范围与rhs 的选择范围完全相同,则返回true ;否则返回false

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