QTextBlockFormat Class
QTextBlockFormatクラスは、QTextDocument のテキスト・ブロックの書式情報を提供します。
ヘッダー | #include <QTextBlockFormat> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui) |
qmake: | QT += gui |
継承: | QTextFormat |
- 継承メンバを含む全メンバのリスト
- QTextBlockFormatは、リッチテキスト処理APIと 暗黙の共有クラスの一部です。
注意:このクラスの関数はすべてリエントラントです。
パブリック型
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() で設定し、最初の行のインデントはsetTextIndent() で設定します。
行間はsetLineHeight() で設定し、lineHeight() とlineHeightType() で取得する。使用可能な行間の種類は、LineHeightTypes enumにある。
改行の有効/無効はsetNonBreakableLines() で設定できます。
段落の背景を塗るブラシはsetBackground() で設定します。また、setProperty() 関数でOutlinePen
、ForegroundBrush
、BackgroundBrush
QTextFormat::Property の値を指定することで、テキストの外観をカスタマイズできます。
テ キ ス ト ブ ロ ッ ク が リ ス ト の一部であ る と き は、 listFormat() 関数で リ ス ト 形式を指定す る こ と も で き ます。
QTextBlock およびQTextCharFormatも参照 。
メンバ型ドキュメント
enum QTextBlockFormat::LineHeightTypes
この列挙型は、段落をサポートする様々なタイプの行間を記述します。
定数 | 値 | 説明 |
---|---|---|
QTextBlockFormat::SingleHeight | 0 | これはデフォルトの行の高さです。 |
QTextBlockFormat::ProportionalHeight | 1 | これは、行に比例した行間を設定します(パーセンテージ)。例えば、ダブルスペースの場合は200に設定します。 |
QTextBlockFormat::FixedHeight | 2 | 行の高さを固定行の高さ(ピクセル単位)に設定します。 |
QTextBlockFormat::MinimumHeight | 3 | 行の高さの最小値を設定します(ピクセル単位)。 |
QTextBlockFormat::LineDistanceHeight | 4 | 指定した行間の高さ(ピクセル単位)を追加します。 |
lineHeight(),lineHeightType(),setLineHeight()も参照 。
enum class QTextBlockFormat::MarkerType
この列挙型は、リスト項目が持つことのできるマーカーのタイプを記述します。リスト項目(QTextBlock::textList ()がリストを返す段落)にマーカーがある場合、通常の箇条書きの代わりに表示されます。このように、チェック可能なリスト項目は、QTextListFormat::style() で指定された箇条書きの種類をリスト全体で上書きすることで、同じリスト内でプレーンなリスト項目と混在させることができます。
定数 | 値 | 説明 |
---|---|---|
QTextBlockFormat::MarkerType::NoMarker | 0 | これはデフォルトです: リスト項目の箇条書きが表示されます。 |
QTextBlockFormat::MarkerType::Unchecked | 1 | リスト項目の箇条書きの代わりに、チェックされていないチェックボックスが表示されます。 |
QTextBlockFormat::MarkerType::Checked | 2 | リスト項目の箇条書きの代わりに、チェックされたチェックボックスが表示されます。 |
将来的には、他のタイプの段落装飾を指定するために拡張されるかもしれません。
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 enum で記述された方法でheightType に依存している。
LineHeightTypes 、lineHeight()、lineHeightType()も参照 。
void QTextBlockFormat::setMarker(QTextBlockFormat::MarkerType marker)
段落の横に表示する装飾のタイプをmarker に設定します。例えば、リスト項目は、その箇条書きの代わりとしてチェックボックスで飾ることができます。デフォルトはNoMarker
です。
marker()も参照してください 。
void QTextBlockFormat::setNonBreakableLines(bool b)
b が真の場合、段落内の行は改行不可として扱われ、そうでない場合は改行可能である。
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()も参照 ください。
© 2025 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.