QTextList 类

The QTextList class provides a decorated list of items in a QTextDocument . 更多...

头: #include <QTextList>
qmake: QT += gui
继承: QTextBlockGroup

注意: 此类的所有函数 可重入 .

公共函数

void add (const QTextBlock & block )
int count () const
QTextListFormat format () const
QTextBlock item (int i ) const
int itemNumber (const QTextBlock & block ) const
QString itemText (const QTextBlock & block ) const
void remove (const QTextBlock & block )
void removeItem (int i )
void setFormat (const QTextListFormat & format )

静态公共成员

const QMetaObject staticMetaObject

额外继承成员

详细描述

The QTextList class provides a decorated list of items in a QTextDocument .

A list contains a sequence of text blocks, each of which is marked with a bullet point or other symbol. Multiple levels of lists can be used, and the automatic numbering feature provides support for ordered numeric and alphabetical lists.

Lists are created by using a text cursor to insert an empty list at the current position or by moving existing text into a new list. The QTextCursor::insertList () function inserts an empty block into the document at the cursor position, and makes it the first item in a list.

    QTextListFormat listFormat;
    if (list) {
        listFormat = list->format();
        listFormat.setIndent(listFormat.indent() + 1);
    }
    listFormat.setStyle(QTextListFormat::ListDisc);
    cursor.insertList(listFormat);
					

The QTextCursor::createList () function takes the contents of the cursor's current block and turns it into the first item of a new list.

The cursor's current list is found with QTextCursor::currentList ().

The number of items in a list is given by count (). Each item can be obtained by its index in the list with the item () function. Similarly, the index of a given item can be found with itemNumber (). The text of each item can be found with the itemText () 函数。

Note that the items in the list may not be adjacent elements in the document. For example, the top-level items in a multi-level list will be separated by the items in lower levels of the list.

List items can be deleted by index with the removeItem () 函数。 remove () deletes the specified item in the list.

The list's format is set with setFormat () and read with format (). The format describes the decoration of the list itself, and not the individual items.

另请参阅 QTextBlock , QTextListFormat ,和 QTextCursor .

成员函数文档编制

void QTextList:: add (const QTextBlock & block )

Makes the given block part of the list.

另请参阅 remove () 和 removeItem ().

int QTextList:: count () const

Returns the number of items in the list.

QTextListFormat QTextList:: format () const

Returns the list's format.

另请参阅 setFormat ().

QTextBlock QTextList:: item ( int i ) const

返回 i -th text block in the list.

另请参阅 count () 和 itemText ().

int QTextList:: itemNumber (const QTextBlock & block ) const

Returns the index of the list item that corresponds to the given block . Returns -1 if the block was not present in the list.

QString QTextList:: itemText (const QTextBlock & block ) const

Returns the text of the list item that corresponds to the given block .

void QTextList:: remove (const QTextBlock & block )

移除给定 block from the list.

另请参阅 add () 和 removeItem ().

void QTextList:: removeItem ( int i )

Removes the item at item position i from the list. When the last item in the list is removed, the list is automatically deleted by the QTextDocument that owns it.

另请参阅 add () 和 remove ().

void QTextList:: setFormat (const QTextListFormat & format )

Sets the list's format to format .

另请参阅 format ().