• PySide 模块
  • PySide.QtGui
  • 内容表

    上一话题

    QTextFrame.iterator

    下一话题

    QTextBlockGroup

    QTextTable

    概要

    函数

    详细描述

    PySide.QtGui.QTextTable class represents a table in a PySide.QtGui.QTextDocument .

    A table is a group of cells ordered into rows and columns. Each table contains at least one row and one column. Each cell contains a block, and is surrounded by a frame.

    Tables are usually created and inserted into a document with the QTextCursor.insertTable() function. For example, we can insert a table with three rows and two columns at the current cursor position in an editor using the following lines of code:

    cursor = QTextCursor(editor.textCursor())
    cursor.movePosition(QTextCursor.Start)
    table = cursor.insertTable(rows, columns, tableFormat)
    										

    The table format is either defined when the table is created or changed later with PySide.QtGui.QTextTable.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 PySide.QtGui.QTextTable.resize() , or by using PySide.QtGui.QTextTable.insertRows() , PySide.QtGui.QTextTable.insertColumns() , PySide.QtGui.QTextTable.removeRows() ,或 PySide.QtGui.QTextTable.removeColumns() 。使用 PySide.QtGui.QTextTable.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 PySide.QtGui.QTextTable.rowStart() and PySide.QtGui.QTextTable.rowEnd() functions to obtain cursors at the start and end of each row.

    Rows and columns within a PySide.QtGui.QTextTable can be merged and split using the PySide.QtGui.QTextTable.mergeCells() and PySide.QtGui.QTextTable.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.

    ../../_images/texttable-split.png

    Suppose we have a 2x3 table of names and addresses. To merge both columns in the first row we invoke PySide.QtGui.QTextTable.mergeCells() with row = 0, column = 0, numRows = 1 and numColumns = 2.

    table.mergeCells(0, 0, 1, 2)
    															
    ../../_images/texttable-merge.png

    This gives us the following table. To split the first row of the table back into two cells, we invoke the PySide.QtGui.QTextTable.splitCell() function with numRows and numCols = 1.

    table.splitCell(0, 0, 1, 1)
    															
    ../../_images/texttable-split.png This results in the original table.
    class PySide.QtGui. QTextTable ( doc )
    参数: doc PySide.QtGui.QTextDocument
    PySide.QtGui.QTextTable. appendColumns ( count )
    参数: count PySide.QtCore.int

    追加 count columns at the right side of the table.

    PySide.QtGui.QTextTable. appendRows ( count )
    参数: count PySide.QtCore.int

    追加 count rows at the bottom of the table.

    PySide.QtGui.QTextTable. cellAt ( row , col )
    参数:
    • row PySide.QtCore.int
    • col PySide.QtCore.int
    返回类型:

    PySide.QtGui.QTextTableCell

    Returns the table cell at the given row and column in the table.

    PySide.QtGui.QTextTable. cellAt ( position )
    参数: position PySide.QtCore.int
    返回类型: PySide.QtGui.QTextTableCell

    这是重载函数。

    Returns the table cell that contains the character at the given position in the document.

    PySide.QtGui.QTextTable. cellAt ( c )
    参数: c PySide.QtGui.QTextCursor
    返回类型: PySide.QtGui.QTextTableCell

    这是重载函数。

    Returns the table cell containing the given cursor .

    PySide.QtGui.QTextTable. columns ( )
    返回类型: PySide.QtCore.int

    Returns the number of columns in the table.

    PySide.QtGui.QTextTable. insertColumns ( pos , num )
    参数:
    • pos PySide.QtCore.int
    • num PySide.QtCore.int

    Inserts a number of columns before the column with the specified index .

    PySide.QtGui.QTextTable. insertRows ( pos , num )
    参数:
    • pos PySide.QtCore.int
    • num PySide.QtCore.int

    Inserts a number of rows before the row with the specified index .

    PySide.QtGui.QTextTable. mergeCells ( row , col , numRows , numCols )
    参数:
    • row PySide.QtCore.int
    • col PySide.QtCore.int
    • numRows PySide.QtCore.int
    • numCols PySide.QtCore.int

    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. If numRows or numCols is less than the current number of rows or columns the cell spans then this method does nothing.

    PySide.QtGui.QTextTable. mergeCells ( cursor )
    参数: cursor PySide.QtGui.QTextCursor

    这是重载函数。

    Merges the cells selected by the provided cursor .

    PySide.QtGui.QTextTable. removeColumns ( pos , num )
    参数:
    • pos PySide.QtCore.int
    • num PySide.QtCore.int

    Removes a number of columns starting with the column at the specified index .

    PySide.QtGui.QTextTable. removeRows ( pos , num )
    参数:
    • pos PySide.QtCore.int
    • num PySide.QtCore.int

    Removes a number of rows starting with the row at the specified index .

    PySide.QtGui.QTextTable. resize ( rows , cols )
    参数:
    • rows PySide.QtCore.int
    • cols PySide.QtCore.int

    Resizes the table to contain the required number of rows and columns .

    PySide.QtGui.QTextTable. rowEnd ( c )
    参数: c PySide.QtGui.QTextCursor
    返回类型: PySide.QtGui.QTextCursor

    Returns a cursor pointing to the end of the row that contains the given cursor .

    PySide.QtGui.QTextTable. rowStart ( c )
    参数: c PySide.QtGui.QTextCursor
    返回类型: PySide.QtGui.QTextCursor

    Returns a cursor pointing to the start of the row that contains the given cursor .

    PySide.QtGui.QTextTable. rows ( )
    返回类型: PySide.QtCore.int

    Returns the number of rows in the table.

    PySide.QtGui.QTextTable. setFormat ( format )
    参数: format PySide.QtGui.QTextTableFormat

    Sets the table's format .

    另请参阅

    PySide.QtGui.QTextTable.format()

    PySide.QtGui.QTextTable. splitCell ( row , col , numRows , numCols )
    参数:
    • row PySide.QtCore.int
    • col PySide.QtCore.int
    • numRows PySide.QtCore.int
    • numCols PySide.QtCore.int

    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 PySide.QtGui.QTextTable.mergeCells() .