Qt Jambi Home

com.trolltech.qt.gui
Class QTextTable

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QObject
              extended by com.trolltech.qt.gui.QTextObject
                  extended by com.trolltech.qt.gui.QTextFrame
                      extended by com.trolltech.qt.gui.QTextTable
All Implemented Interfaces:
QtJambiInterface

public class QTextTable
extends QTextFrame

The QTextTable class represents a table in a 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:

        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, or removeColumns. Use 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 and 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 and 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.)

Original TableSuppose we have a 2x6 table of names and addresses. To merge both columns in the first row we invoke mergeCells with 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);
Split TableThis results in the original table.

See Also:
QTextTableFormat

Nested Class Summary
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Constructor Summary
QTextTable(QTextDocument doc)
          
 
Method Summary
 QTextTableCell cellAt(int position)
          Returns the table cell that contains the character at the given position in the document.
 QTextTableCell cellAt(int row, int col)
          Returns the table cell at the given row and col in the table.
 QTextTableCell cellAt(QTextCursor c)
          Returns the table cell containing the given c.
 int columns()
          Returns the number of columns in the table.
static QTextTable fromNativePointer(QNativePointer nativePointer)
          This function returns the QTextTable instance pointed to by nativePointer
 void insertColumns(int pos, int num)
          Inserts a number of num before the column with the specified pos.
 void insertRows(int pos, int num)
          Inserts a number of num before the row with the specified pos.
 void mergeCells(int row, int col, int numRows, int numCols)
          Merges the cell at the specified row and col with the adjacent cells into one cell.
 void mergeCells(QTextCursor cursor)
          Merges the cells selected by the provided cursor.
 void removeColumns(int pos, int num)
          Removes a number of num starting with the column at the specified pos.
 void removeRows(int pos, int num)
          Removes a number of num starting with the row at the specified pos.
 void resize(int rows, int cols)
          Resizes the table to contain the required number of rows and cols.
 QTextCursor rowEnd(QTextCursor c)
          Returns a cursor pointing to the end of the row that contains the given c.
 int rows()
          Returns the number of rows in the table.
 QTextCursor rowStart(QTextCursor c)
          Returns a cursor pointing to the start of the row that contains the given c.
 void setFormat(QTextTableFormat format)
          Sets the table's format.
 void splitCell(int row, int col, int numRows, int numCols)
          Splits the specified cell at row and col into an array of multiple cells with dimensions specified by numRows and numCols.
 QTextTableFormat tableFormat()
          Returns the table's format.
 
Methods inherited from class com.trolltech.qt.gui.QTextFrame
begin, childFrames, end, firstCursorPosition, firstPosition, frameFormat, lastCursorPosition, lastPosition, parentFrame, setFrameFormat
 
Methods inherited from class com.trolltech.qt.gui.QTextObject
document, format, formatIndex, objectIndex, setFormat
 
Methods inherited from class com.trolltech.qt.core.QObject
blockSignals, childEvent, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
disconnect, disconnect, signalSender
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Constructor Detail

QTextTable

public QTextTable(QTextDocument doc)

Method Detail

cellAt

public final QTextTableCell cellAt(int position)

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


cellAt

public final QTextTableCell cellAt(QTextCursor c)

Returns the table cell containing the given c.


cellAt

public final QTextTableCell cellAt(int row,
                                   int col)

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

See Also:
columns, rows

columns

public final int columns()

Returns the number of columns in the table.

See Also:
rows

tableFormat

public final QTextTableFormat tableFormat()

Returns the table's format.

See Also:
setFormat

insertColumns

public final void insertColumns(int pos,
                                int num)

Inserts a number of num before the column with the specified pos.

See Also:
insertRows, resize, removeRows, removeColumns

insertRows

public final void insertRows(int pos,
                             int num)

Inserts a number of num before the row with the specified pos.

See Also:
resize, insertColumns, removeRows, removeColumns

mergeCells

public final void mergeCells(int row,
                             int col,
                             int numRows,
                             int numCols)

Merges the cell at the specified row and col 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.

See Also:
splitCell

mergeCells

public final void mergeCells(QTextCursor cursor)

Merges the cells selected by the provided cursor.

See Also:
splitCell

removeColumns

public final void removeColumns(int pos,
                                int num)

Removes a number of num starting with the column at the specified pos.

See Also:
insertRows, insertColumns, removeRows, resize

removeRows

public final void removeRows(int pos,
                             int num)

Removes a number of num starting with the row at the specified pos.

See Also:
insertRows, insertColumns, resize, removeColumns

resize

public final void resize(int rows,
                         int cols)

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

See Also:
insertRows, insertColumns, removeRows, removeColumns

rowEnd

public final QTextCursor rowEnd(QTextCursor c)

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

See Also:
rowStart

rowStart

public final QTextCursor rowStart(QTextCursor c)

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

See Also:
rowEnd

rows

public final int rows()

Returns the number of rows in the table.

See Also:
columns

setFormat

public final void setFormat(QTextTableFormat format)

Sets the table's format.

See Also:
format

splitCell

public final void splitCell(int row,
                            int col,
                            int numRows,
                            int numCols)

Splits the specified cell at row and col into an array of multiple cells with dimensions specified by numRows and numCols.

Note: It is only possible to split cells that span multiple rows or columns, such as rows that have been merged using mergeCells.

See Also:
mergeCells

fromNativePointer

public static QTextTable fromNativePointer(QNativePointer nativePointer)
This function returns the QTextTable instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

Qt Jambi Home