QTextLine Class
QTextLineクラスは、QTextLayout。
ヘッダー | #include <QTextLine> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui) |
qmake: | QT += gui |
- 継承メンバを含む全メンバ一覧
- QTextLineはリッチテキスト処理APIの一部です。
注意:このクラスの関数はすべてリエントラントです。
パブリック型
enum | CursorPosition { CursorBetweenCharacters, CursorOnCharacter } |
enum | Edge { Leading, Trailing } |
パブリック関数
QTextLine() | |
qreal | ascent() const |
qreal | cursorToX(int *cursorPos, QTextLine::Edge edge = Leading) const |
qreal | cursorToX(int cursorPos, QTextLine::Edge edge = Leading) const |
qreal | descent() const |
void | draw(QPainter *painter, const QPointF &position) const |
(since 6.5) QList<QGlyphRun> | glyphRuns(int from, int length, QTextLayout::GlyphRunRetrievalFlags retrievalFlags) const |
QList<QGlyphRun> | glyphRuns(int from = -1, int length = -1) const |
qreal | height() const |
qreal | horizontalAdvance() const |
bool | isValid() const |
qreal | leading() const |
bool | leadingIncluded() const |
int | lineNumber() const |
QRectF | naturalTextRect() const |
qreal | naturalTextWidth() const |
QPointF | position() const |
QRectF | rect() const |
void | setLeadingIncluded(bool included) |
void | setLineWidth(qreal width) |
void | setNumColumns(int numColumns) |
void | setNumColumns(int numColumns, qreal alignmentWidth) |
void | setPosition(const QPointF &pos) |
int | textLength() const |
int | textStart() const |
qreal | width() const |
qreal | x() const |
int | xToCursor(qreal x, QTextLine::CursorPosition cpos = CursorBetweenCharacters) const |
qreal | y() const |
詳細説明
テキスト行は通常QTextLayout::createLine() によって作成される。
作成後、setLineWidth() またはsetNumColumns() 関数を使用して行を埋めることができます。線は、それが占める矩形rect()、その座標x()およびy()、そのtextLength()、width()およびnaturalTextWidth()、ならびにテキストに対する相対位置ascent()およびdescent()を含む多くの属性を持つ。行から見たカーソルの位置はcursorToX() で、その逆はxToCursor() で知ることができる。行の移動はsetPosition() で行うことができる。
メンバ型ドキュメント
enum QTextLine::CursorPosition
定数 | 定数 |
---|---|
QTextLine::CursorBetweenCharacters | 0 |
QTextLine::CursorOnCharacter | 1 |
enum QTextLine::Edge
定数 | 値 |
---|---|
QTextLine::Leading | 0 |
QTextLine::Trailing | 1 |
メンバ関数ドキュメント
QTextLine::QTextLine()
無効な行を作成する。
qreal QTextLine::ascent() const
線の上り坂を返す。
qreal QTextLine::cursorToX(int *cursorPos, QTextLine::Edge edge = Leading) const
カーソル位置cursorPos を、edge を考慮して、行内の対応する x 位置に変換する。
cursorPos が有効なカーソル位置でない場合、代わりに最も近い有効なカーソル位置が使用され、cursorPos はこの有効なカーソル位置を指すように変更される。
xToCursor()も参照のこと 。
qreal QTextLine::cursorToX(int cursorPos, QTextLine::Edge edge = Leading) const
これはオーバーロードされた関数である。
qreal QTextLine::descent() const
線の下降を返します。
void QTextLine::draw(QPainter *painter, const QPointF &position) const
与えられたpainter 上に、指定されたposition で線を描きます。
[since 6.5]
QList<QGlyphRun> QTextLine::glyphRuns(int from, int length, QTextLayout::GlyphRunRetrievalFlags retrievalFlags) const
from とlength で定義 さ れてい る 範囲内のキ ャ ラ ク タ に対す る 、 こ のQTextLine 内のすべてのグ リ フのグ リ フ イ ンデ ッ ク ス と 位置を返 し ます。from イ ンデ ッ ク スは、QTextLayout を含むテ キ ス ト の先頭か ら の相対位置であ り 、 こ の範囲は、 関数textStart () ・textLength () で与え ら れたQTextLine の範囲内でなければな り ません。
retrievalFlags は、QGlyphRun のどのプロパテ ィ を レ イ アウ ト か ら 取得す る か を指定 し ます。割り当てとメモリ消費を最小限に抑えるため、後でアクセスする必要のあるプロパティのみを含むように設定する必要があります。
from が負の場合、デフォルトはtextStart() となり、length が負の場合、デフォルトはtextLength() の戻り値となります。
この関数は Qt 6.5 で導入されました。
QTextLayout::glyphRuns()も参照してください 。
QList<QGlyphRun> QTextLine::glyphRuns(int from = -1, int length = -1) const
これはオーバーロードされた関数です。
from とlength で定義された範囲内のキ ャ ラ ク タ に対す る 、 こ のQTextLine 内のすべてのグ リ フ のグ リ フ イ ンデ ッ ク ス と 位置を返 し ます。from イ ンデ ッ ク スは、QTextLayout を含むテ キ ス ト の先頭か ら の相対値であ り 、 こ の範囲は、 関数textStart () とtextLength () に よ っ て与え ら れたQTextLine の範囲内でなければな り ません。
from が負の場合、デフォルトはtextStart() となり、length が負の場合、デフォルトはtextLength() の戻り値となる。
注: これは glyphRuns(from, length, QTextLayout::GlyphRunRetrievalFlag::GlyphIndexes | QTextLayout::GlyphRunRetrievalFlag::GlyphPositions) を呼び出すのと同じです。
QTextLayout::glyphRuns()も参照してください 。
qreal QTextLine::height() const
行の高さを返す。これは、leading を含まない場合はascent() +descent() に等しい。先行が含まれる場合、これはascent() +descent() +leading() に等しい。
ascent()、descent()、leading()、setLeadingIncluded()も参照 。
qreal QTextLine::horizontalAdvance() const
テキストの水平方向の進み具合を返します。テキストの前進とは、その位置から、テキストが自然に描画される次の位置までの距離のことです。
テキスト行の位置にアドバンスを加え、これを2行目のテキスト行の位置として使用することで、2行を隙間なく並べて配置することができます。
bool QTextLine::isValid() const
このテキスト行が有効な場合はtrue
を返し、そうでない場合はfalse
を返す。
qreal QTextLine::leading() const
行の先頭を返す。
ascent()、descent() およびheight()も参照 。
bool QTextLine::leadingIncluded() const
行の高さに正の先行が含まれる場合はtrue
を返し、そうでない場合はfalse
を返す。
デフォルトでは、行頭は含まれません。
setLeadingIncluded()も参照 。
int QTextLine::lineNumber() const
テキストエンジン内の行の位置を返します。
QRectF QTextLine::naturalTextRect() const
線で囲まれた矩形を返す。
qreal QTextLine::naturalTextWidth() const
テキストが占める行の幅を返す。これは常に <= towidth() であり、改行位置を変えずに layout() で使用できる最小幅となります。
QPointF QTextLine::position() const
テキストレイアウトの位置に対する行の相対位置を返します。
setPosition()も参照してください 。
QRectF QTextLine::rect() const
線の外接矩形を返します。
x()、y()、textLength() およびwidth()も参照 。
void QTextLine::setLeadingIncluded(bool included)
included が true の場合は行の高さに正の行頭を含める。
デフォルトでは、行頭は含まれません。
負方向の行頭は無視されるので、テキスト行を使用するコードでは行をオーバーラップさせて処理しなければならないことに注意してください。
leadingIncluded()も参照 。
void QTextLine::setLineWidth(qreal width)
与えられたwidth で行を埋める。行はその開始位置から、行に収まるだけの文字で埋められます。テキストが行末で分割できない場合は、次の空白またはテキストの終わりまで追加文字で埋められます。
void QTextLine::setNumColumns(int numColumns)
行を並べる。行は開始位置からnumColumns で指定された文字数で埋められる。テ キ ス ト がnumColumns キ ャ ラ ク タ ま で分割で き ない と き は、 行は次の空白ま たはテ キ ス ト の終わりま で同 じ キ ャ ラ ク タ 数で埋め ら れます。
void QTextLine::setNumColumns(int numColumns, qreal alignmentWidth)
行を並べる。行は開始位置からnumColumns で指定された文字数で埋められる。テ キ ス ト がnumColumns キ ャ ラ ク タ ま で分割で き ない と き は、 行は次の空白ま たはテ キ ス ト の末尾ま で同 じ キ ャ ラ ク タ 数で埋め ら れます。指定 さ れたalignmentWidth は、 整列のための参照幅 と し て用い ら れます。
void QTextLine::setPosition(const QPointF &pos)
行をpos の位置に移動する。
position()も参照のこと 。
int QTextLine::textLength() const
行のテキストの長さを返します。
naturalTextWidth()も参照 。
int QTextLine::textStart() const
QTextLayout に渡された文字列の先頭から行頭までを返す。
qreal QTextLine::width() const
layout() 関数で指定した行の幅を返す。
naturalTextWidth()、x()、y()、textLength() およびrect()も参照 。
qreal QTextLine::x() const
行の x 位置を返す。
rect()、y()、textLength() およびwidth()も参照 。
int QTextLine::xToCursor(qreal x, QTextLine::CursorPosition cpos = CursorBetweenCharacters) const
x 座標x を、カーソル位置タイプcpos に応じて、最も近いカーソル位置に変換する。結果のカーソル位置には、編集前領域のテキストが含まれる可能性があることに注意。
cursorToX()も参照のこと 。
qreal QTextLine::y() const
線の y 位置を返す。
x()、rect()、textLength() およびwidth()も参照 。
© 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.