QTextTable 类表示的表格在 QTextDocument . 更多...
头: | #include <QTextTable> |
CMake: |
find_package(Qt6 COMPONENTS Gui REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Gui) |
qmake: | QT += gui |
继承: | QTextFrame |
注意: 此类的所有函数 可重入 .
void | appendColumns (int count ) |
void | appendRows (int count ) |
QTextTableCell | cellAt (int row , int column ) const |
QTextTableCell | cellAt (int position ) const |
QTextTableCell | cellAt (const QTextCursor & cursor ) const |
int | columns () const |
QTextTableFormat | format () const |
void | insertColumns (int index , int columns ) |
void | insertRows (int index , int rows ) |
void | mergeCells (int row , int column , int numRows , int numCols ) |
void | mergeCells (const QTextCursor & cursor ) |
void | removeColumns (int index , int columns ) |
void | removeRows (int index , int rows ) |
void | resize (int rows , int columns ) |
QTextCursor | rowEnd (const QTextCursor & cursor ) const |
QTextCursor | rowStart (const QTextCursor & cursor ) const |
int | rows () const |
void | setFormat (const QTextTableFormat & format ) |
void | splitCell (int row , int column , int numRows , int numCols ) |
表格是排序成行列的一组单元格。每个表格至少包含一行一列。每个单元格都包含块,且由框架环绕。
通常,创建并将表格插入文档是采用 QTextCursor::insertTable () 函数。例如,可以使用以下代码行在编辑器当前光标位置处,插入具有 3 行 2 列的表格:
QTextCursor cursor(editor->textCursor()); cursor.movePosition(QTextCursor::Start); QTextTable *table = cursor.insertTable(rows, columns, tableFormat);
The table format is either defined when the table is created or changed later with setFormat ().
The table currently being edited by the cursor is found with QTextCursor::currentTable (). This allows its format or dimensions to be changed after it has been inserted into a document.
A table's size can be changed with resize (), or by using insertRows (), insertColumns (), removeRows (),或 removeColumns ()。使用 cellAt () to retrieve table cells.
The starting and ending positions of table rows can be found by moving a cursor within a table, and using the rowStart () 和 rowEnd () functions to obtain cursors at the start and end of each row.
Rows and columns within a QTextTable can be merged and split using the mergeCells () 和 splitCell () functions. However, only cells that span multiple rows or columns can be split. (Merging or splitting does not increase or decrease the number of rows and columns.)
Note that if you have merged multiple columns and rows into one cell, you will not be able to split the merged cell into new cells spanning over more than one row or column. To be able to split cells spanning over several rows and columns you need to do this over several iterations.
Suppose we have a 2x3 table of names and addresses. To merge both columns in the first row we invoke
mergeCells
() 采用
row
= 0,
column
= 0,
numRows
= 1 and
numColumns
= 2.
table->mergeCells(0, 0, 1, 2); |
|
This gives us the following table. To split the first row of the table back into two cells, we invoke the
splitCell
() function with
numRows
and
numCols
= 1.
table->splitCell(0, 0, 1, 1); |
|
This results in the original table. |
另请参阅 QTextTableFormat .
追加 count 列在表格右侧。
另请参阅 insertColumns (), insertRows (), resize (), removeRows (), removeColumns (),和 appendRows ().
追加 count rows at the bottom of the table.
另请参阅 insertColumns (), insertRows (), resize (), removeRows (), removeColumns (),和 appendColumns ().
Returns the table cell at the given row and column in the table.
这是重载函数。
Returns the table cell that contains the character at the given position in the document.
这是重载函数。
Returns the table cell containing the given cursor .
Returns the number of columns in the table.
另请参阅 rows ().
Returns the table's format.
另请参阅 setFormat ().
Inserts a number of columns before the column with the specified index .
另请参阅 insertRows (), resize (), removeRows (), removeColumns (), appendRows (),和 appendColumns ().
Inserts a number of rows before the row with the specified index .
另请参阅 resize (), insertColumns (), removeRows (), removeColumns (), appendRows (),和 appendColumns ().
Merges the cell at the specified row and column with the adjacent cells into one cell. The new cell will span numRows rows and numCols columns. This method does nothing if numRows or numCols is less than the current number of rows or columns spanned by the cell.
另请参阅 splitCell ().
这是重载函数。
Merges the cells selected by the provided cursor .
另请参阅 splitCell ().
Removes a number of columns starting with the column at the specified index .
另请参阅 insertRows (), insertColumns (), removeRows (), resize (), appendRows (),和 appendColumns ().
Removes a number of rows starting with the row at the specified index .
另请参阅 insertRows (), insertColumns (), resize (), removeColumns (), appendRows (),和 appendColumns ().
Resizes the table to contain the required number of rows and columns .
另请参阅 insertRows (), insertColumns (), removeRows (),和 removeColumns ().
Returns a cursor pointing to the end of the row that contains the given cursor .
另请参阅 rowStart ().
Returns a cursor pointing to the start of the row that contains the given cursor .
另请参阅 rowEnd ().
Returns the number of rows in the table.
另请参阅 columns ().
Sets the table's format .
另请参阅 format ().
Splits the specified cell at row and column into an array of multiple cells with dimensions specified by numRows and numCols .
注意: It is only possible to split cells that span multiple rows or columns, such as rows that have been merged using mergeCells ().
另请参阅 mergeCells ().