このページでは

QTextBlockFormat Class

QTextBlockFormat クラスは、QTextDocument 内のテキストブロックの書式設定情報を提供します。詳細...

ヘッダー: #include <QTextBlockFormat>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
継承元: QTextFormat

注:このクラスのすべての関数は再入可能です。

パブリック型

enum LineHeightTypes { SingleHeight, ProportionalHeight, FixedHeight, MinimumHeight, LineDistanceHeight }
enum class MarkerType { NoMarker, Unchecked, Checked }

パブリック関数

QTextBlockFormat()
Qt::Alignment alignment() const
qreal bottomMargin() const
int headingLevel() const
int indent() const
bool isValid() const
qreal leftMargin() const
qreal lineHeight() const
qreal lineHeight(qreal scriptLineHeight, qreal scaling = 1.0) const
int lineHeightType() const
QTextBlockFormat::MarkerType marker() const
bool nonBreakableLines() const
QTextFormat::PageBreakFlags pageBreakPolicy() const
qreal rightMargin() const
void setAlignment(Qt::Alignment alignment)
void setBottomMargin(qreal margin)
void setHeadingLevel(int level)
void setIndent(int indentation)
void setLeftMargin(qreal margin)
void setLineHeight(qreal height, int heightType)
void setMarker(QTextBlockFormat::MarkerType marker)
void setNonBreakableLines(bool b)
void setPageBreakPolicy(QTextFormat::PageBreakFlags policy)
void setRightMargin(qreal margin)
void setTabPositions(const QList<QTextOption::Tab> &tabs)
void setTextIndent(qreal indent)
void setTopMargin(qreal margin)
QList<QTextOption::Tab> tabPositions() const
qreal textIndent() const
qreal topMargin() const

詳細な説明

ドキュメントは、QTextBlock オブジェクトによって表されるブロックのリストで構成されています。各ブロックには、テキストの段落、表、リスト、画像など、何らかの項目を含めることができます。すべてのブロックには、その特性を指定する QTextBlockFormat が関連付けられています。

左から右、および右から左の言語に対応するため、setLayoutDirection() を使用してブロックの方向を設定できます。段落の配置は、setAlignment() で設定します。余白は、setTopMargin()、setBottomMargin()、setLeftMargin()、setRightMargin() によって制御されます。全体的なインデントはsetIndent() で設定し、1 行目のインデントはsetTextIndent() で設定します。

行間隔はsetLineHeight() で設定され、lineHeight() およびlineHeightType() を通じて取得されます。利用可能な行間隔の種類は、LineHeightTypes 列挙型に定義されています。

改行は、setNonBreakableLines() を使用して有効または無効にできます。

段落の背景の描画に使用するブラシは、setBackground() で設定され、テキストの外観のその他の側面は、setProperty() 関数と、OutlinePen 、ForegroundBrush 、およびBackgroundBrush QTextFormat::Property の値を使用してカスタマイズできます。

テキストブロックがリストの一部である場合、listFormat() 関数を使用してリスト形式を指定することもできます。

QTextBlock およびQTextCharFormatも参照してください 。

メンバ型のドキュメント

enum QTextBlockFormat::LineHeightTypes

この列挙型は、段落が持つことができるさまざまな行間設定の種類を表します。

定数値説明
QTextBlockFormat::SingleHeight0これはデフォルトの行高(シングル行間)です。
QTextBlockFormat::ProportionalHeight1行間を(パーセンテージで)行に比例して設定します。たとえば、2倍行間に設定するには 200 を指定します。
QTextBlockFormat::FixedHeight2行高さを固定値(ピクセル単位)に設定します。
QTextBlockFormat::MinimumHeight3これで最小行高(ピクセル単位)が設定されます。
QTextBlockFormat::LineDistanceHeight4行間に指定した高さ(ピクセル単位)を追加します。

lineHeight()、lineHeightType()、およびsetLineHeight()も参照してください 。

enum class QTextBlockFormat::MarkerType

この列挙型は、リスト項目が持つことができるマーカーの種類を定義します。リスト項目(QTextBlock::textList() がリストを返す段落)にマーカーが設定されている場合、通常の箇条書き記号の代わりにそのマーカーが表示されます。 これにより、同じリスト内でチェック可能なリスト項目と通常のリスト項目を混在させることができ、リスト全体に対してQTextListFormat::style()で指定された箇条書き記号の種類を上書きすることができます。

定数値説明
QTextBlockFormat::MarkerType::NoMarker0これがデフォルトです。リスト項目の箇条書き記号が表示されます。
QTextBlockFormat::MarkerType::Unchecked1値リスト項目の箇条書き記号の代わりに、チェックされていないチェックボックスが表示されます。
QTextBlockFormat::MarkerType::Checked2リスト項目の箇条書き記号の代わりに、チェックが入っていないチェックボックスが表示されます。

将来的には、他の種類の段落装飾を指定できるよう拡張される可能性があります。

関連項目: QTextListFormat::style()。

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

QTextBlockFormat::QTextBlockFormat()

新しい QTextBlockFormat を生成します。

Qt::Alignment QTextBlockFormat::alignment() const

段落の配置情報を返します。

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

qreal QTextBlockFormat::bottomMargin() const

段落の下マージンを返します。

setBottomMargin() およびtopMargin()も参照してください 。

int QTextBlockFormat::headingLevel() const

見出しである場合はその段落の見出しレベルを返し、そうでない場合は0を返します。

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

int QTextBlockFormat::indent() const

段落のインデントを返します。

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

bool QTextBlockFormat::isValid() const

このブロック形式が有効な場合は `true ` を返し、そうでない場合は `false` を返します。

qreal QTextBlockFormat::leftMargin() const

段落の左余白を返します。

setLeftMargin()、rightMargin()、およびindent()も参照してください 。

qreal QTextBlockFormat::lineHeight() const

これは、段落の LineHeight プロパティを返します。

LineHeightTypes 、setLineHeight()、およびlineHeightType()も参照してください 。

qreal QTextBlockFormat::lineHeight(qreal scriptLineHeight, qreal scaling = 1.0) const

scriptLineHeight で指定されたスクリプト行の高さと、指定されたscaling 係数に基づいて、段落内の行の高さを返します。

返される値は、指定された段落の LineHeightType およびその段落に設定されている LineHeight 設定にも依存します。

スケーリングは、固定ピクセル数を含む行高に対して、印刷用に適切に拡大縮小するために必要です。

LineHeightTypes 、setLineHeight()、およびlineHeightType()も参照してください 。

int QTextBlockFormat::lineHeightType() const

これは、段落の LineHeightType プロパティを返します。

LineHeightTypes 、setLineHeight()、およびlineHeight()も参照してください 。

QTextBlockFormat::MarkerType QTextBlockFormat::marker() const

マーカーが設定されている場合はそのマーカーを返し、設定されていない場合は `NoMarker ` を返します。

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

bool QTextBlockFormat::nonBreakableLines() const

段落内の行が改行不可の場合は `true ` を返し、そうでない場合は `false` を返します。

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

QTextFormat::PageBreakFlags QTextBlockFormat::pageBreakPolicy() const

その段落に現在設定されている改ページポリシーを返します。デフォルトは `QTextFormat::PageBreak_Auto` です。

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

qreal QTextBlockFormat::rightMargin() const

段落の右余白を返します。

setRightMargin() およびleftMargin()も参照してください 。

void QTextBlockFormat::setAlignment(Qt::Alignment alignment)

段落のalignment を設定します。

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

void QTextBlockFormat::setBottomMargin(qreal margin)

段落の下端margin を設定します。

bottomMargin()、setTopMargin()、setLeftMargin()、およびsetRightMargin()も参照してください 。

void QTextBlockFormat::setHeadingLevel(int level)

段落の見出しレベルlevel を設定します。ここで、1 は最上位の見出しタイプ(通常、可能な限り大きな見出しフォントサイズが適用されます)であり、値が大きくなるにつれて文書内の階層が深くなり(通常、フォントサイズも小さくなります)。 たとえば、HTML の H1 タグを読み込む場合、見出しレベルは 1 に設定されます。見出しレベルを設定しても、フォントサイズは自動的に変更されません。ただし、QTextDocumentFragment::fromHtml() を使用すると、見出しレベルとフォントサイズが同時に設定されます。

段落が見出しでない場合は、レベルを 0(デフォルト)に設定する必要があります。

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

void QTextBlockFormat::setIndent(int indentation)

段落のindentation を設定します。余白は、setLeftMargin() およびsetTextIndent() を使用して、インデントとは独立して設定されます。indentation は整数であり、文書全体の標準インデント値と掛け合わされ、その結果として段落の実際のインデント値が決定されます。

indent() およびQTextDocument::indentWidth()も参照してください 。

void QTextBlockFormat::setLeftMargin(qreal margin)

段落の左インデントを設定します。margin 。インデントは、setIndent() を使用して個別に適用することもできます。

leftMargin()、setRightMargin()、setTopMargin()、およびsetBottomMargin()も参照してください 。

void QTextBlockFormat::setLineHeight(qreal height, int heightType)

段落の行高を、height で指定された値に設定します。この値は、LineHeightTypes 列挙型で説明されている通り、heightType に依存します。

LineHeightTypes 、lineHeight()、およびlineHeightType()も参照してください 。

void QTextBlockFormat::setMarker(QTextBlockFormat::MarkerType marker)

段落と一緒に表示される装飾の種類を `marker` に設定します。たとえば、リスト項目には、箇条書き記号の代わりに、チェック済みまたは未チェックのチェックボックスを装飾として付けることができます。デフォルトは `NoMarker` です。

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

void QTextBlockFormat::setNonBreakableLines(bool b)

b が true の場合、段落内の行は改行不可として扱われます。そうでない場合は、改行可能として扱われます。

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

void QTextBlockFormat::setPageBreakPolicy(QTextFormat::PageBreakFlags policy)

その段落の改ページポリシーを「policy 」に設定します。

「pageBreakPolicy()」も参照してください 。

void QTextBlockFormat::setRightMargin(qreal margin)

段落の右端を設定しますmargin 。

rightMargin()、setLeftMargin()、setTopMargin()、およびsetBottomMargin()も参照してください 。

void QTextBlockFormat::setTabPositions(const QList<QTextOption::Tab> &tabs)

テキストブロックのタブ位置を、tabs で指定された位置に設定します。

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

void QTextBlockFormat::setTextIndent(qreal indent)

ブロックの最初の行のindent を設定します。これにより、段落の最初の行を他の行とは異なるインデントにすることができ、テキストの読みやすさが向上します。

関連項目: textIndent()、setLeftMargin()、setRightMargin()、setTopMargin()、setBottomMargin()も参照してください 。

void QTextBlockFormat::setTopMargin(qreal margin)

段落の上端margin を設定します。

topMargin()、setBottomMargin()、setLeftMargin()、およびsetRightMargin()も参照してください 。

QList<QTextOption::Tab> QTextBlockFormat::tabPositions() const

そのテキストブロックに対して定義されているタブ位置のリストを返します。

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

qreal QTextBlockFormat::textIndent() const

段落のテキストのインデントを返します。

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

qreal QTextBlockFormat::topMargin() const

段落の上マージンを返します。

setTopMargin() およびbottomMargin()も参照してください 。

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