Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QTextTable Class Reference

\reentrant More...

#include <qtexttable.h>

+ Inheritance diagram for QTextTable:
+ Collaboration diagram for QTextTable:

Public Member Functions

 QTextTable (QTextDocument *doc)
 
 ~QTextTable ()
 
void resize (int rows, int cols)
 Resizes the table to contain the required number of rows and columns.
 
void insertRows (int pos, int num)
 Inserts a number of rows before the row with the specified index.
 
void insertColumns (int pos, int num)
 Inserts a number of columns before the column with the specified index.
 
void appendRows (int count)
 
void appendColumns (int count)
 
void removeRows (int pos, int num)
 Removes a number of rows starting with the row at the specified index.
 
void removeColumns (int pos, int num)
 Removes a number of columns starting with the column at the specified index.
 
void mergeCells (int row, int col, int numRows, int numCols)
 
void mergeCells (const QTextCursor &cursor)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
void splitCell (int row, int col, int numRows, int numCols)
 
int rows () const
 Returns the number of rows in the table.
 
int columns () const
 Returns the number of columns in the table.
 
QTextTableCell cellAt (int row, int col) const
 Returns the table cell at the given row and column in the table.
 
QTextTableCell cellAt (int position) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the table cell that contains the character at the given position in the document.
 
QTextTableCell cellAt (const QTextCursor &c) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the table cell containing the given cursor.
 
QTextCursor rowStart (const QTextCursor &c) const
 Returns a cursor pointing to the start of the row that contains the given cursor.
 
QTextCursor rowEnd (const QTextCursor &c) const
 Returns a cursor pointing to the end of the row that contains the given cursor.
 
void setFormat (const QTextTableFormat &format)
 Sets the table's format.
 
QTextTableFormat format () const
 Returns the table's format.
 
- Public Member Functions inherited from QTextFrame
 QTextFrame (QTextDocument *doc)
 Creates a new empty frame for the text document.
 
 ~QTextFrame ()
 Destroys the text frame.
 
void setFrameFormat (const QTextFrameFormat &format)
 Sets the frame's format.
 
QTextFrameFormat frameFormat () const
 Returns the frame's format.
 
QTextCursor firstCursorPosition () const
 Returns the first cursor position inside the frame.
 
QTextCursor lastCursorPosition () const
 Returns the last cursor position inside the frame.
 
int firstPosition () const
 Returns the first document position inside the frame.
 
int lastPosition () const
 Returns the last document position inside the frame.
 
QTextFrameLayoutDatalayoutData () const
 
void setLayoutData (QTextFrameLayoutData *data)
 
QList< QTextFrame * > childFrames () const
 Returns a (possibly empty) list of the frame's child frames.
 
QTextFrameparentFrame () const
 Returns the frame's parent frame.
 
iterator begin () const
 Returns an iterator pointing to the first document element inside the frame.
 
iterator end () const
 Returns an iterator pointing to the position past the last document element inside the frame.
 
- Public Member Functions inherited from QTextObject
QTextFormat format () const
 Returns the text object's format.
 
int formatIndex () const
 Returns the index of the object's format in the document's internal list of formats.
 
QTextDocumentdocument () const
 Returns the document this object belongs to.
 
int objectIndex () const
 Returns the object index of this object.
 
- Public Member Functions inherited from QObject
Q_INVOKABLE QObject (QObject *parent=nullptr)
 Constructs an object with parent object parent.
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects.
 
virtual bool event (QEvent *event)
 This virtual function receives events to an object and should return true if the event e was recognized and processed.
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 Filters events if this object has been installed as an event filter for the watched object.
 
QString objectName () const
 
Q_WEAK_OVERLOAD void setObjectName (const QString &name)
 Sets the object's name to name.
 
void setObjectName (QAnyStringView name)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
QBindable< QStringbindableObjectName ()
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false.
 
bool isWindowType () const
 Returns true if the object is a window; otherwise returns false.
 
bool isQuickItemType () const
 Returns true if the object is a QQuickItem; otherwise returns false.
 
bool signalsBlocked () const noexcept
 Returns true if signals are blocked; otherwise returns false.
 
bool blockSignals (bool b) noexcept
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it).
 
QThreadthread () const
 Returns the thread in which the object lives.
 
bool moveToThread (QThread *thread QT6_DECL_NEW_OVERLOAD_TAIL)
 Changes the thread affinity for this object and its children and returns true on success.
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 This is an overloaded function that will start a timer of type timerType and a timeout of interval milliseconds.
 
int startTimer (std::chrono::nanoseconds time, Qt::TimerType timerType=Qt::CoarseTimer)
 
void killTimer (int id)
 Kills the timer with timer identifier, id.
 
void killTimer (Qt::TimerId id)
 
template<typename T >
findChild (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns the child of this object that can be cast into type T and that is called name, or \nullptr if there is no such object.
 
template<typename T >
QList< T > findChildren (QAnyStringView aName, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects.
 
template<typename T >
findChild (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
template<typename T >
QList< T > findChildren (Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
const QObjectListchildren () const
 Returns a list of child objects.
 
void setParent (QObject *parent)
 Makes the object a child of parent.
 
void installEventFilter (QObject *filterObj)
 Installs an event filter filterObj on this object.
 
void removeEventFilter (QObject *obj)
 Removes an event filter object obj from this object.
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=nullptr, const QObject *receiver=nullptr, const char *member=nullptr) const
 
bool disconnect (const QObject *receiver, const char *member=nullptr) const
 
void dumpObjectTree () const
 Dumps a tree of children to the debug output.
 
void dumpObjectInfo () const
 Dumps information about signal connections, etc.
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value.
 
bool setProperty (const char *name, QVariant &&value)
 
QVariant property (const char *name) const
 Returns the value of the object's name property.
 
QList< QByteArraydynamicPropertyNames () const
 
QBindingStoragebindingStorage ()
 
const QBindingStoragebindingStorage () const
 
QObjectparent () const
 Returns a pointer to the parent object.
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false.
 

Friends

class QTextTableCell
 

Additional Inherited Members

- Public Types inherited from QTextFrame
typedef iterator Iterator
 Qt-style synonym for QTextFrame::iterator.
 
- Public Slots inherited from QObject
void deleteLater ()
 \threadsafe
 
- Signals inherited from QObject
void destroyed (QObject *=nullptr)
 This signal is emitted immediately before the object obj is destroyed, after any instances of QPointer have been notified, and cannot be blocked.
 
void objectNameChanged (const QString &objectName, QPrivateSignal)
 This signal is emitted after the object's name has been changed.
 
- Static Public Member Functions inherited from QObject
static QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
 \threadsafe
 
static QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::ContextTypeForFunctor< Func2 >::ContextType *context, Func2 &&slot, Qt::ConnectionType type=Qt::AutoConnection)
 
template<typename Func1 , typename Func2 >
static QMetaObject::Connection connect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, Func2 &&slot)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 \threadsafe
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static bool disconnect (const QMetaObject::Connection &)
 Disconnect a connection.
 
template<typename Func1 , typename Func2 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiver, Func2 slot)
 
template<typename Func1 >
static bool disconnect (const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const QObject *receiver, void **zero)
 
- Protected Member Functions inherited from QTextFrame
 QTextFrame (QTextFramePrivate &p, QTextDocument *doc)
 
- Protected Member Functions inherited from QTextObject
 QTextObject (QTextDocument *doc)
 Creates a new QTextObject for the given document.
 
 ~QTextObject ()
 Destroys the text object.
 
void setFormat (const QTextFormat &format)
 Sets the text object's format.
 
 QTextObject (QTextObjectPrivate &p, QTextDocument *doc)
 
- Protected Member Functions inherited from QObject
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns \nullptr.
 
int senderSignalIndex () const
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal.
 
bool isSignalConnected (const QMetaMethod &signal) const
 
virtual void timerEvent (QTimerEvent *event)
 This event handler can be reimplemented in a subclass to receive timer events for the object.
 
virtual void childEvent (QChildEvent *event)
 This event handler can be reimplemented in a subclass to receive child events.
 
virtual void customEvent (QEvent *event)
 This event handler can be reimplemented in a subclass to receive custom events.
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
 QObject (QObjectPrivate &dd, QObject *parent=nullptr)
 
- Protected Attributes inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Properties inherited from QObject
QString objectName
 the name of this object
 

Detailed Description

\reentrant

The QTextTable class represents a table in a QTextDocument. \inmodule QtGui

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:

\codeline

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.

\table 80% \row

  • \inlineimage texttable-split.png 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.

\row

  • \inlineimage texttable-merge.png
  • 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.

\row

  • \inlineimage texttable-split.png Split Table
  • This results in the original table. \endtable
See also
QTextTableFormat

Definition at line 62 of file qtexttable.h.

Constructor & Destructor Documentation

◆ QTextTable()

QTextTable::QTextTable ( QTextDocument * doc)
explicit

Definition at line 525 of file qtexttable.cpp.

◆ ~QTextTable()

QTextTable::~QTextTable ( )

Destroys the table.

Definition at line 534 of file qtexttable.cpp.

Member Function Documentation

◆ appendColumns()

void QTextTable::appendColumns ( int count)
Since
4.5 Appends count columns at the right side of the table.
See also
insertColumns(), insertRows(), resize(), removeRows(), removeColumns(), appendRows()

Definition at line 814 of file qtexttable.cpp.

References columns(), and insertColumns().

Referenced by QTextMarkdownImporter::cbEnterBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ appendRows()

void QTextTable::appendRows ( int count)
Since
4.5 Appends count rows at the bottom of the table.
See also
insertColumns(), insertRows(), resize(), removeRows(), removeColumns(), appendColumns()

Definition at line 803 of file qtexttable.cpp.

References insertRows(), and rows().

Referenced by QTextMarkdownImporter::cbEnterBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ cellAt() [1/3]

QTextTableCell QTextTable::cellAt ( const QTextCursor & c) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the table cell containing the given cursor.

Definition at line 590 of file qtexttable.cpp.

References cellAt().

+ Here is the call graph for this function:

◆ cellAt() [2/3]

QTextTableCell QTextTable::cellAt ( int position) const

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the table cell that contains the character at the given position in the document.

Definition at line 564 of file qtexttable.cpp.

References QSet< T >::begin(), d, it, map, pos, position(), and QTextTableCell.

+ Here is the call graph for this function:

◆ cellAt() [3/3]

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

Definition at line 546 of file qtexttable.cpp.

References d, and QTextTableCell.

Referenced by QTextMarkdownImporter::cbEnterBlock(), cellAt(), mergeCells(), removeColumns(), removeRows(), rowEnd(), rowStart(), and splitCell().

+ Here is the caller graph for this function:

◆ columns()

int QTextTable::columns ( ) const

Returns the number of columns in the table.

See also
rows()

Definition at line 1228 of file qtexttable.cpp.

References d.

Referenced by appendColumns(), QTextMarkdownImporter::cbEnterBlock(), QTextMarkdownImporter::cbLeaveBlock(), mergeCells(), resize(), and setFormat().

+ Here is the caller graph for this function:

◆ format()

QTextTableFormat QTextTable::format ( ) const
inline

Returns the table's format.

See also
setFormat()

Definition at line 92 of file qtexttable.h.

References QTextObject::format(), and QTextFormat::toTableFormat().

Referenced by insertColumns(), removeColumns(), and setFormat().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insertColumns()

void QTextTable::insertColumns ( int index,
int columns )

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

See also
insertRows(), resize(), removeRows(), removeColumns(), appendRows(), appendColumns()

Definition at line 702 of file qtexttable.cpp.

References d, fmt, format(), i, it, QTextUndoCommand::MoveCursor, QTextObject::objectIndex(), pos, position(), Q_ASSERT, qMax(), QTextBeginningOfFrame, QTextObject::setFormat(), QTextCharFormat::setTableCellColumnSpan(), and QTextCharFormat::setTableCellRowSpan().

Referenced by appendColumns(), and resize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ insertRows()

void QTextTable::insertRows ( int index,
int rows )

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

See also
resize(), insertColumns(), removeRows(), removeColumns(), appendRows(), appendColumns()

Definition at line 636 of file qtexttable.cpp.

References d, fmt, i, it, QTextUndoCommand::MoveCursor, QTextObject::objectIndex(), pos, Q_ASSERT, QTextBeginningOfFrame, and QTextCharFormat::setTableCellRowSpan().

Referenced by appendRows(), and resize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mergeCells() [1/2]

void QTextTable::mergeCells ( const QTextCursor & cursor)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.1

Merges the cells selected by the provided cursor.

See also
splitCell()

Definition at line 1122 of file qtexttable.cpp.

References cursor, and mergeCells().

+ Here is the call graph for this function:

◆ mergeCells() [2/2]

void QTextTable::mergeCells ( int row,
int column,
int numRows,
int numCols )
Since
4.1

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.

See also
splitCell()

Definition at line 962 of file qtexttable.cpp.

References QTextFrame::begin(), QTextCursor::block(), cellAt(), QSet< T >::cend(), QTextTableCell::column(), columns(), d, QTextTableCell::firstCursorPosition(), QTextTableCell::firstPosition(), fmt, QTextTableCell::format(), QTextCursorPrivate::fromPosition(), i, QTextTableCell::isValid(), it, j, QTextBlock::length(), pos, Q_ASSERT, qMin(), QTextTableCell::row(), rows(), and QTextCharFormat::tableCellRowSpan().

Referenced by QTextMarkdownImporter::cbLeaveBlock(), and mergeCells().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeColumns()

void QTextTable::removeColumns ( int index,
int columns )

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

See also
insertRows(), insertColumns(), removeRows(), resize(), appendRows(), appendColumns()

Definition at line 888 of file qtexttable.cpp.

References cellAt(), d, QTextFrame::firstPosition(), fmt, format(), it, QTextTableCell::lastPosition(), pos, QTextObject::setFormat(), and QTextCharFormat::tableCellColumnSpan().

Referenced by resize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ removeRows()

void QTextTable::removeRows ( int index,
int rows )

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

See also
insertRows(), insertColumns(), resize(), removeColumns(), appendRows(), appendColumns()

Definition at line 826 of file qtexttable.cpp.

References cellAt(), d, QTextFrame::firstPosition(), fmt, it, QTextTableCell::lastPosition(), pos, and QTextCharFormat::tableCellRowSpan().

Referenced by resize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resize()

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

Definition at line 602 of file qtexttable.cpp.

References columns(), d, insertColumns(), insertRows(), removeColumns(), removeRows(), and rows().

+ Here is the call graph for this function:

◆ rowEnd()

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

Definition at line 1266 of file qtexttable.cpp.

References cellAt(), d, QTextCursorPrivate::fromPosition(), QTextTableCell::isValid(), it, and QTextTableCell::row().

+ Here is the call graph for this function:

◆ rows()

int QTextTable::rows ( ) const

Returns the number of rows in the table.

See also
columns()

Definition at line 1214 of file qtexttable.cpp.

References d.

Referenced by appendRows(), QTextMarkdownImporter::cbEnterBlock(), QTextMarkdownImporter::cbLeaveBlock(), mergeCells(), and resize().

+ Here is the caller graph for this function:

◆ rowStart()

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

Definition at line 1245 of file qtexttable.cpp.

References cellAt(), d, QTextCursorPrivate::fromPosition(), QTextTableCell::isValid(), it, and QTextTableCell::row().

+ Here is the call graph for this function:

◆ setFormat()

void QTextTable::setFormat ( const QTextTableFormat & format)

Sets the table's format.

See also
format()

Definition at line 1287 of file qtexttable.cpp.

References columns(), fmt, format(), QTextTableFormat::setColumns(), and QTextObject::setFormat().

+ Here is the call graph for this function:

◆ splitCell()

void QTextTable::splitCell ( int row,
int column,
int numRows,
int numCols )
Since
4.1

Splits the specified cell at row and column 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()

Definition at line 1143 of file qtexttable.cpp.

References QTextFrame::begin(), cellAt(), QTextTableCell::column(), d, QTextTableCell::firstPosition(), fmt, QTextTableCell::format(), i, QTextTableCell::isValid(), it, QTextTableCell::lastPosition(), QTextBeginningOfFrame, QTextTableCell::row(), and QTextCharFormat::tableCellRowSpan().

+ Here is the call graph for this function:

Friends And Related Symbol Documentation

◆ QTextTableCell

friend class QTextTableCell
friend

Definition at line 97 of file qtexttable.h.

Referenced by cellAt(), and cellAt().


The documentation for this class was generated from the following files: