本页内容

QTextTableCell Class

QTextTableCell 类表示QTextTable 中一个单元格的属性。更多内容...

头文件: #include <QTextTableCell>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui

注意:该类中的所有函数均为可重入函数。

公共函数

QTextTableCell()
QTextTableCell(const QTextTableCell &other)
~QTextTableCell()
QTextFrame::iterator begin() const
int column() const
int columnSpan() const
QTextFrame::iterator end() const
QTextCursor firstCursorPosition() const
QTextCharFormat format() const
bool isValid() const
QTextCursor lastCursorPosition() const
int row() const
int rowSpan() const
void setFormat(const QTextCharFormat &format)
int tableCellFormatIndex() const
bool operator!=(const QTextTableCell &other) const
QTextTableCell &operator=(const QTextTableCell &other)
bool operator==(const QTextTableCell &other) const

详细描述

表格单元格是属于表格的文档结构片段。表格将单元格按特定的行和列进行排序;单元格也可以跨越多个列和行。

单元格通常是在使用QTextCursor::insertTable() 将表格插入文档时创建的,但在调整表格大小时,也会创建和销毁单元格。

单元格包含有关其在表格中位置的信息;您可以获取单元格的row() 和column() 编号,以及其rowSpan() 和columnSpan() 值。

单元的format()描述了其内容的默认字符格式。firstCursorPosition()和lastCursorPosition()函数用于获取单元在文档中的范围。

另请参阅 QTextTable 和QTextTableFormat 。

成员函数文档

QTextTableCell::QTextTableCell()

构建一个无效的表格单元格。

另请参阅 isValid()。

QTextTableCell::QTextTableCell(const QTextTableCell &other)

复制构造函数。根据other 单元创建一个新的QTextTableCell对象。

[noexcept] QTextTableCell::~QTextTableCell()

删除该表格单元格。

QTextFrame::iterator QTextTableCell::begin() const

返回一个指向该表单元格起始位置的帧迭代器。

另请参阅 end()。

int QTextTableCell::column() const

返回包含该单元格的表中的列号。

另请参阅 row()。

int QTextTableCell::columnSpan() const

返回该单元格跨越的列数。默认值为 1。

另请参阅 rowSpan()。

QTextFrame::iterator QTextTableCell::end() const

返回一个指向该表单元格末尾的帧迭代器。

另请参阅 begin()。

QTextCursor QTextTableCell::firstCursorPosition() const

返回该单元格中第一个有效的光标位置。

另请参阅 lastCursorPosition()。

QTextCharFormat QTextTableCell::format() const

返回单元格的字符格式。

另请参阅 setFormat()。

bool QTextTableCell::isValid() const

如果这是一个有效的表格单元格,则返回true ;否则返回false。

QTextCursor QTextTableCell::lastCursorPosition() const

返回该单元格中最后一个有效的光标位置。

另请参阅 firstCursorPosition()。

int QTextTableCell::row() const

返回包含该单元格的表格中的行号。

另请参阅 column()。

int QTextTableCell::rowSpan() const

返回该单元格所覆盖的行数。默认值为 1。

另请参阅 columnSpan()。

void QTextTableCell::setFormat(const QTextCharFormat &format)

将单元格的字符格式设置为format 。例如,这可用于更改整个单元格的背景色:

QTextTableCell cell = table->cellAt(2, 3);
QTextCharFormat format = cell.format();
format.setBackground(Qt::blue);
cell.setFormat(format);

请注意,无法通过此函数更改单元格的行或列范围。您必须改用QTextTable::mergeCells 和QTextTable::splitCell 。

另请参阅 format()。

int QTextTableCell::tableCellFormatIndex() const

返回该 tableCell 格式在文档内部格式列表中的索引。

另请参阅 QTextDocument::allFormats()。

bool QTextTableCell::operator!=(const QTextTableCell &other) const

如果该单元格对象与other 单元格对象所描述的单元格不同,则返回true ;否则返回false 。

QTextTableCell &QTextTableCell::operator=(const QTextTableCell &other)

将other 表格单元格分配给此表格单元格。

bool QTextTableCell::operator==(const QTextTableCell &other) const

如果该单元格对象与other 单元格对象描述的是同一个单元格,则返回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.