このページでは

QTextList Class

QTextList クラスは、QTextDocument 内の項目を装飾したリストを提供します。詳細...

ヘッダー: #include <QTextList>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
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)

詳細な説明

リストは一連のテキストブロックで構成され、各ブロックには箇条書きのマークやその他の記号が付いています。複数のレベルのリストを使用することができ、自動番号付け機能により、番号付きリストやアルファベット順のリストがサポートされています。

リストは、テキストカーソルを使用して現在の位置に空のリストを挿入するか、既存のテキストを新しいリストに移動することで作成されます。QTextCursor::insertList() 関数は、カーソルの位置に空のブロックをドキュメントに挿入し、それをリストの最初の項目にします。

    QTextListFormat listFormat;
    if (list) {
        listFormat = list->format();
        listFormat.setIndent(listFormat.indent() + 1);
    }

    listFormat.setStyle(QTextListFormat::ListDisc);
    cursor.insertList(listFormat);

QTextCursor::createList() 関数は、カーソルの現在のブロックの内容を受け取り、それを新しいリストの最初の項目に変換します。

カーソルの現在のリストは、QTextCursor::currentList() によって取得されます。

リスト内の項目数は、count() によって取得できます。各項目は、item() 関数を使用して、リスト内でのインデックスによって取得できます。同様に、特定の項目のインデックスは、itemNumber() を使用して取得できます。各項目のテキストは、itemText() 関数を使用して取得できます。

なお、リスト内の項目は、ドキュメント内で隣接する要素とは限らないことに注意してください。たとえば、多階層リストの最上位の項目は、リストの下位階層にある項目によって区切られます。

リストの項目は、removeItem() 関数を使用してインデックスを指定して削除できます。remove() は、リスト内の指定された項目を削除します。

リストのフォーマットは `setFormat()` で設定し、`format()` で読み取ります。このフォーマットは、個々の項目ではなく、リスト自体の装飾を記述するものです。

QTextBlock 、QTextListFormat 、およびQTextCursorも参照してください 。

メンバ関数のドキュメント

void QTextList::add(const QTextBlock &block)

指定されたblock をリストの一部にします。

remove() およびremoveItem()も参照してください 。

int QTextList::count() const

リストに含まれる項目の数を返します。

QTextListFormat QTextList::format() const

リストの形式を返します。

setFormat()も参照してください 。

QTextBlock QTextList::item(int i) const

リスト内のi 番目のテキストブロックを返します。

count() およびitemText()も参照してください 。

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

指定されたblock に対応するリスト項目のインデックスを返します。リストにそのブロックが存在しない場合は、-1を返します。

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

指定されたblock に対応するリスト項目のテキストを返します。

void QTextList::remove(const QTextBlock &block)

指定されたblock をリストから削除します。

add() およびremoveItem()も参照してください 。

void QTextList::removeItem(int i)

リスト内のi の位置にある項目を削除します。リストの最後の項目が削除されると、そのリストを所有するQTextDocument によってリストは自動的に削除されます。

add() およびremove()も参照してください 。

void QTextList::setFormat(const QTextListFormat &format)

リストの書式を「format 」に設定します。

format()も参照してください 。

© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.