QTextBlock Class

QTextBlock 클래스는 QTextDocument.. . 더보기...

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

참고: 이 클래스의 모든 함수는 재인용됩니다.

공용 유형

공용 함수

QTextBlock(const QTextBlock &other)
QTextBlock::iterator begin() const
QTextBlockFormat blockFormat() const
int blockFormatIndex() const
int blockNumber() const
QTextCharFormat charFormat() const
int charFormatIndex() const
void clearLayout()
bool contains(int position) const
const QTextDocument *document() const
QTextBlock::iterator end() const
int firstLineNumber() const
bool isValid() const
bool isVisible() const
QTextLayout *layout() const
int length() const
int lineCount() const
QTextBlock next() const
int position() const
QTextBlock previous() const
int revision() const
void setLineCount(int count)
void setRevision(int rev)
void setUserData(QTextBlockUserData *data)
void setUserState(int state)
void setVisible(bool visible)
QString text() const
Qt::LayoutDirection textDirection() const
QList<QTextLayout::FormatRange> textFormats() const
QTextList *textList() const
QTextBlockUserData *userData() const
int userState() const
bool operator!=(const QTextBlock &other) const
bool operator<(const QTextBlock &other) const
QTextBlock &operator=(const QTextBlock &other)
bool operator==(const QTextBlock &other) const

상세 설명

텍스트 블록은 텍스트의 블록 또는 단락을 QTextDocument 에 캡슐화합니다. QTextBlock은 QTextDocuments의 블록/단락 구조에 대한 읽기 전용 액세스를 제공합니다. 주로 QTextDocument 의 시각적 표현을 위해 자신만의 레이아웃을 구현하거나 문서를 반복하여 사용자 지정 형식으로 내용을 작성하려는 경우에 사용됩니다.

텍스트 블록은 상위 문서에 의해 생성됩니다. 새 텍스트 블록을 만들거나 문서 내용을 검토하는 동안 문서 내용을 수정해야 하는 경우 QTextCursor 에서 제공하는 커서 기반 인터페이스를 대신 사용하세요.

각 텍스트 블록은 document()의 특정 position()에 위치합니다. 블록의 콘텐츠는 text() 함수를 사용하여 얻을 수 있습니다. length () 함수는 문서 내에서 블록의 크기(서식 문자 포함)를 결정합니다. 블록의 시각적 속성은 텍스트 layout(), charFormat() 및 blockFormat()에 의해 결정됩니다.

next() 및 previous() 함수는 반복 프로세스 중에 문서가 다른 방법으로 수정되지 않는다는 조건 하에 문서에서 연속적으로 유효한 블록에 대한 반복을 가능하게 합니다. 블록은 순서대로 반환되지만 인접한 블록은 문서 구조의 다른 위치에서 올 수 있다는 점에 유의하세요. 블록의 유효성은 isValid()를 호출하여 확인할 수 있습니다.

operator==()는 두 블록이 같은지 비교하고, operator!=()는 두 블록이 같지 않은지 비교하며, operator<()는 같은 문서에서 블록이 다른 블록보다 앞서는지 판단하는 비교 연산자를 제공하여 블록 작업을 더 쉽게 할 수 있도록 합니다.

QTextBlockFormat, QTextCharFormat, QTextFragment참조하세요 .

멤버 유형 문서

QTextBlock::Iterator

QTextBlock::iterator 의 Qt 스타일 동의어.

멤버 함수 문서

QTextBlock::QTextBlock(const QTextBlock &other)

other 텍스트 블록의 속성을 이 텍스트 블록에 복사합니다.

QTextBlock::iterator QTextBlock::begin() const

텍스트 블록의 시작 부분을 가리키는 텍스트 블록 이터레이터를 반환합니다.

end()도 참조하세요 .

QTextBlockFormat QTextBlock::blockFormat() const

블록별 속성을 설명하는 QTextBlockFormat 을 반환합니다.

charFormat()도 참조하세요 .

int QTextBlock::blockFormatIndex() const

텍스트 블록의 형식에 대한 문서의 내부 블록 형식 목록에 대한 색인을 반환합니다.

QTextDocument::allFormats()도 참조하세요 .

int QTextBlock::blockNumber() const

이 블록의 번호를 반환하거나 블록이 유효하지 않은 경우 -1을 반환합니다.

QTextCursor::blockNumber()도 참조하세요 .

QTextCharFormat QTextBlock::charFormat() const

블록의 문자 형식을 설명하는 QTextCharFormat 을 반환합니다. 블록의 문자 형식은 빈 블록에 텍스트를 삽입할 때 사용됩니다.

blockFormat()도 참조하세요 .

int QTextBlock::charFormatIndex() const

텍스트 블록의 문자 형식에 대한 문서의 내부 문자 형식 목록에 대한 인덱스를 반환합니다.

QTextDocument::allFormats()도 참조하세요 .

void QTextBlock::clearLayout()

블록의 콘텐츠를 배치하고 표시하는 데 사용되는 QTextLayout 을 지웁니다.

layout()도 참조하세요 .

bool QTextBlock::contains(int position) const

지정된 position 이 텍스트 블록 내에 있으면 true 을 반환하고, 그렇지 않으면 false 을 반환합니다.

const QTextDocument *QTextBlock::document() const

이 텍스트 블록이 속한 텍스트 문서를 반환하거나, 텍스트 블록이 문서에 속하지 않은 경우 nullptr 을 반환합니다.

QTextBlock::iterator QTextBlock::end() const

텍스트 블록의 끝을 가리키는 텍스트 블록 이터레이터를 반환합니다.

begin(), next() 및 previous()도 참조하세요 .

int QTextBlock::firstLineNumber() const

이 블록의 첫 번째 줄 번호를 반환하거나 블록이 유효하지 않은 경우 -1을 반환합니다. 레이아웃에서 지원하지 않는 한 줄 번호는 블록 번호와 동일합니다.

QTextBlock::blockNumber()도 참조하세요 .

bool QTextBlock::isValid() const

이 텍스트 블록이 유효하면 true 을 반환하고, 그렇지 않으면 false 을 반환합니다.

bool QTextBlock::isVisible() const

블록이 표시되면 true 을 반환하고, 그렇지 않으면 false 을 반환합니다.

setVisible()도 참조하세요 .

QTextLayout *QTextBlock::layout() const

블록의 콘텐츠를 레이아웃하고 표시하는 데 사용되는 QTextLayout 을 반환합니다.

반환된 QTextLayout 객체는 QAbstractTextDocumentLayout 서브클래스의 documentChanged 구현에서만 수정할 수 있습니다. 외부에서 변경 사항을 적용하면 정의되지 않은 동작이 발생합니다.

clearLayout()도 참조하세요 .

int QTextBlock::length() const

블록의 길이를 문자 단위로 반환합니다.

참고: 반환되는 길이에는 모든 서식 지정 문자(예: 개행)가 포함됩니다.

text(), charFormat() 및 blockFormat()도 참조하세요 .

int QTextBlock::lineCount() const

줄 수를 반환합니다. 모든 문서 레이아웃이 이 기능을 지원하는 것은 아닙니다.

setLineCount()도 참조하세요 .

QTextBlock QTextBlock::next() const

이 블록 뒤에 있는 문서 내 텍스트 블록을 반환하거나, 이 블록이 마지막 블록인 경우 빈 텍스트 블록을 반환합니다.

다음 블록은 이 블록과 다른 프레임이나 테이블에 있을 수 있습니다.

previous(), begin() 및 end()도 참조하세요 .

int QTextBlock::position() const

문서 내에서 블록의 첫 번째 문자의 인덱스를 반환합니다.

QTextBlock QTextBlock::previous() const

이 블록 이전의 문서에 있는 텍스트 블록을 반환하거나, 이 블록이 첫 번째 블록인 경우 빈 텍스트 블록을 반환합니다.

이전 블록은 이 블록과 다른 프레임이나 테이블에 있을 수 있습니다.

next(), begin() 및 end()도 참조하세요 .

int QTextBlock::revision() const

블록 리비전을 반환합니다.

setRevision() 및 QTextDocument::revision()도 참조하세요 .

void QTextBlock::setLineCount(int count)

줄 수를 count 로 설정합니다.

lineCount()도 참조하세요 .

void QTextBlock::setRevision(int rev)

블록 리비전을 rev 로 설정합니다.

revision() 및 QTextDocument::revision()도 참조하세요 .

void QTextBlock::setUserData(QTextBlockUserData *data)

지정된 data 객체를 텍스트 블록에 첨부합니다.

QTextBlockUserData 사용자 정의 설정을 저장하는 데 사용할 수 있습니다. 소유권은 기본 텍스트 문서로 전달되며, 해당 텍스트 블록이 삭제되면 제공된 QTextBlockUserData 객체가 삭제됩니다. 사용자 데이터 객체는 실행 취소 기록에 저장되지 않으므로 텍스트 블록의 삭제를 실행 취소한 후에는 사용할 수 없습니다.

예를 들어 IDE에서 프로그래밍 편집기를 작성하는 경우 통합 디버거를 위해 사용자가 코드에서 시각적으로 중단점을 설정할 수 있도록 할 수 있습니다. 프로그래밍 편집기에서 한 줄의 텍스트는 일반적으로 QTextBlock 에 해당합니다. QTextBlockUserData 인터페이스를 사용하면 개발자는 예를 들어 사용자가 중단점을 설정한 소스 코드의 어느 줄에 있는지와 같은 각 QTextBlock 에 대한 데이터를 저장할 수 있습니다. 물론 외부에 저장할 수도 있지만 QTextDocument 안에 저장하면 예를 들어 사용자가 관련 줄을 삭제하면 자동으로 삭제됩니다. 실행 취소/다시 실행 스택에 영향을 줄 수 있는 QTextFormat 의 사용자 정의 속성을 사용하지 않고 QTextDocument 에 사용자 정의 정보를 저장하는 방법일 뿐입니다.

userData()도 참조하세요 .

void QTextBlock::setUserState(int state)

텍스트 블록에 지정된 state 정수 값을 저장합니다. 예를 들어 구문 분석 상태를 저장하는 구문 하이라이터에서 유용하게 사용할 수 있습니다.

userState()도 참조하세요 .

void QTextBlock::setVisible(bool visible)

블록의 가시성을 visible 로 설정합니다.

isVisible()도 참조하세요 .

QString QTextBlock::text() const

블록의 콘텐츠를 일반 텍스트로 반환합니다.

length(), charFormat() 및 blockFormat()도 참조하세요 .

Qt::LayoutDirection QTextBlock::textDirection() const

확인된 텍스트 방향을 반환합니다.

블록에 명시적인 방향이 설정되어 있지 않으면 블록 콘텐츠에서 방향을 확인합니다. Qt::LeftToRight 또는 Qt::RightToLeft 을 반환합니다.

QTextFormat::layoutDirection(), QString::isRightToLeft() 및 Qt::LayoutDirection참조하세요 .

QList<QTextLayout::FormatRange> QTextBlock::textFormats() const

블록의 텍스트 형식 옵션을 QTextCharFormat 의 연속 범위 목록으로 반환합니다. 범위의 문자 형식은 범위 경계 내에 텍스트를 삽입할 때 사용됩니다.

charFormat() 및 blockFormat()도 참조하세요 .

QTextList *QTextBlock::textList() const

블록이 목록 항목을 나타내는 경우 해당 항목이 속한 목록을 반환하고, 그렇지 않으면 nullptr 을 반환합니다.

QTextBlockUserData *QTextBlock::userData() const

setUserData() 또는 nullptr 로 설정된 경우 QTextBlockUserData 객체에 대한 포인터를 반환합니다.

setUserData()도 참조하세요 .

int QTextBlock::userState() const

이전에 setUserState() 또는 -1로 설정한 정수 값을 반환합니다.

setUserState()도 참조하세요 .

bool QTextBlock::operator!=(const QTextBlock &other) const

이 텍스트 블록이 other 텍스트 블록과 다른 경우 true 을 반환합니다.

bool QTextBlock::operator<(const QTextBlock &other) const

이 텍스트 블록이 문서의 other 텍스트 블록 앞에 있는 경우 true 을 반환합니다.

QTextBlock &QTextBlock::operator=(const QTextBlock &other)

other 텍스트 블록을 이 텍스트 블록에 할당합니다.

bool QTextBlock::operator==(const QTextBlock &other) const

이 텍스트 블록이 other 텍스트 블록과 동일한 경우 true 을 반환합니다.

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