CopperSpice API  1.9.1
QTextTable Class Reference

The QTextTable class represents a table in a QTextDocument. More...

Inheritance diagram for QTextTable:
QTextFrame QTextObject QObject

Public Methods

void appendColumns (int count)
 
void appendRows (int count)
 
QTextTableCell cellAt (const QTextCursor &cursor) const
 
QTextTableCell cellAt (int position) const
 
QTextTableCell cellAt (int row, int column) const
 
int columns () const
 
QTextTableFormat format () const
 
void insertColumns (int index, int numColumns)
 
void insertRows (int index, int numRows)
 
void mergeCells (const QTextCursor &cursor)
 
void mergeCells (int row, int column, int numRows, int numColumns)
 
void removeColumns (int index, int numColumns)
 
void removeRows (int index, int numRows)
 
void resize (int rows, int columns)
 
QTextCursor rowEnd (const QTextCursor &cursor) const
 
int rows () const
 
QTextCursor rowStart (const QTextCursor &cursor) const
 
void setFormat (const QTextTableFormat &format)
 
void splitCell (int row, int column, int numRows, int numColumns)
 
- Public Methods inherited from QTextFrame
 QTextFrame (QTextDocument *document)
 
 ~QTextFrame ()
 
iterator begin () const
 
QList< QTextFrame * > childFrames () const
 
iterator end () const
 
QTextCursor firstCursorPosition () const
 
int firstPosition () const
 
QTextFrameFormat frameFormat () const
 
QTextCursor lastCursorPosition () const
 
int lastPosition () const
 
QTextFrame * parentFrame () const
 
void setFrameFormat (const QTextFrameFormat &format)
 
- Public Methods inherited from QTextObject
QTextDocumentdocument () const
 
QTextFormat format () const
 
int formatIndex () const
 
int objectIndex () const
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool event (QEvent *event)
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 

Friends

class QTextTableCell
 

Additional Inherited Members

- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 
- Public Slots inherited from QObject
void deleteLater ()
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 
- Protected Methods inherited from QTextObject
 QTextObject (QTextDocument *document)
 
 ~QTextObject ()
 
void setFormat (const QTextFormat &format)
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 
- Properties inherited from QObject
 objectName
 

Detailed Description

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

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.

Original Table Suppose we have a 2x3 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 numColumns = 1.
table->splitCell(0, 0, 1, 1);
Split Table This results in the original table.
See also
QTextTableFormat

Method Documentation

void QTextTable::appendColumns ( int  count)

Appends count columns at the right side of the table.

See also
insertColumns(), insertRows(), resize(), removeRows(), removeColumns(), appendRows()
void QTextTable::appendRows ( int  count)

Appends count rows at the bottom of the table.

See also
insertColumns(), insertRows(), resize(), removeRows(), removeColumns(), appendColumns()
QTextTableCell QTextTable::cellAt ( const QTextCursor cursor) const

Returns the table cell containing the given cursor.

QTextTableCell QTextTable::cellAt ( int  position) const

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

QTextTableCell QTextTable::cellAt ( int  row,
int  column 
) const

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

See also
columns(), rows()
int QTextTable::columns ( ) const

Returns the number of columns in the table.

See also
rows()
QTextTableFormat QTextTable::format ( ) const
inline

Returns the table's format.

See also
setFormat()
void QTextTable::insertColumns ( int  index,
int  numColumns 
)

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

See also
insertRows(), resize(), removeRows(), removeColumns(), appendRows(), appendColumns()
void QTextTable::insertRows ( int  index,
int  numRows 
)

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

See also
resize(), insertColumns(), removeRows(), removeColumns(), appendRows(), appendColumns()
void QTextTable::mergeCells ( const QTextCursor cursor)

Merges the cells selected by the provided cursor.

See also
splitCell()
void QTextTable::mergeCells ( int  row,
int  column,
int  numRows,
int  numColumns 
)

Merges the cell at the specified row and column with the adjacent cells into one cell. The new cell will span numRows and numColumns. If numRows or numColumns is less than the current number of rows or columns the cell spans then this method does nothing.

See also
splitCell()
void QTextTable::removeColumns ( int  index,
int  numColumns 
)

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

See also
insertRows(), insertColumns(), removeRows(), resize(), appendRows(), appendColumns()
void QTextTable::removeRows ( int  index,
int  numRows 
)

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

See also
insertRows(), insertColumns(), resize(), removeColumns(), appendRows(), appendColumns()
void QTextTable::resize ( int  rows,
int  columns 
)

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

See also
insertRows(), insertColumns(), removeRows(), removeColumns()
QTextCursor QTextTable::rowEnd ( const QTextCursor cursor) const

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

See also
rowStart()
int QTextTable::rows ( ) const

Returns the number of rows in the table.

See also
columns()
QTextCursor QTextTable::rowStart ( const QTextCursor cursor) const

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

See also
rowEnd()
void QTextTable::setFormat ( const QTextTableFormat format)

Sets the table's format.

See also
format()
void QTextTable::splitCell ( int  row,
int  column,
int  numRows,
int  numColumns 
)

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

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()