이 페이지에서

QTextLine Class

QTextLine 클래스는 QTextLayout 내부의 한 줄의 텍스트를 나타냅니다. 더 보기...

헤더: #include <QTextLine>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui

참고: 이 클래스의 모든 함수는 재진입 가능합니다.

공개 유형

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::CursorBetweenCharacters0
QTextLine::CursorOnCharacter1

enum QTextLine::Edge

상수상수
QTextLine::Leading0
QTextLine::Trailing1

멤버 함수 설명서

QTextLine::QTextLine()

잘못된 줄을 생성합니다.

qreal QTextLine::ascent() const

줄의 상승량을 반환합니다.

descent() 및 height()도 참조하십시오 .

qreal QTextLine::cursorToX(int *cursorPos, QTextLine::Edge edge = Leading) const

edge 를 고려하여 커서 위치 cursorPos 를 해당 줄 내부의 x 위치로 변환합니다.

cursorPos 가 유효한 커서 위치가 아닌 경우, 가장 가까운 유효한 커서 위치가 대신 사용되며, cursorPos 는 이 유효한 커서 위치를 가리키도록 수정됩니다.

xToCursor()도 참조하십시오 .

qreal QTextLine::cursorToX(int cursorPos, QTextLine::Edge edge = Leading) const

이 함수는 오버로드된 함수입니다.

qreal QTextLine::descent() const

해당 라인의 하강량을 반환합니다.

ascent() 및 height()도 참조하십시오 .

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

줄의 높이를 반환합니다. 이 값은 줄 머리글이 포함되지 않은 경우 ascent() + descent()과 같습니다. 줄 머리글이 포함된 경우, 이 값은 ascent() + descent() + leading()과 같습니다.

ascent(), descent(), leading(), setLeadingIncluded()도 참조하십시오 .

qreal QTextLine::horizontalAdvance() const

텍스트의 수평 간격을 반환합니다. 텍스트의 간격이란 현재 위치에서 텍스트가 자연스럽게 그려질 다음 위치까지의 거리를 말합니다.

이 간격을 텍스트 줄의 위치에 더한 다음, 이를 두 번째 텍스트 줄의 위치로 사용하면 두 줄 사이에 틈이 생기지 않게 나란히 배치할 수 있습니다.

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

텍스트가 차지하는 줄의 너비를 반환합니다. 이 값은 항상 ` width()`보다 작거나 같으며, 줄 바꿈 위치를 변경하지 않고 `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()도 참조하십시오 .

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