本页内容

QItemSelectionRange Class

QItemSelectionRange 类用于管理模型中选定项目范围的相关信息。更多内容...

头文件: #include <QItemSelectionRange>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

QItemSelectionRange 的比较

类别可比较类型
相等性QItemSelectionRange

公共函数

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()函数则可用于判断两个范围是否重叠。

另请参阅 《模型/视图编程》、QAbstractItemModel 、QItemSelection 以及QItemSelectionModel 。

成员函数文档

[noexcept default] 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 。

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