QTextObjectInterface Class

QTextObjectInterface 클래스를 사용하면 QTextDocuments에서 사용자 지정 텍스트 객체를 그릴 수 있습니다.. . 더보기...

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

공용 함수

virtual ~QTextObjectInterface()
virtual void drawObject(QPainter *painter, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format) = 0
virtual QSizeF intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format) = 0

상세 설명

텍스트 객체는 텍스트 문서에 있는 하나 이상의 요소 구조를 설명합니다. 예를 들어 HTML에서 가져온 이미지는 텍스트 객체를 사용하여 구현됩니다. 텍스트 객체는 문서가 렌더링될 때 그 요소를 배치하고 그리는 방법을 알고 있습니다.

Qt는 QTextCharFormat 에 사용자 정의 object type 를 등록하여 사용자 정의 텍스트 객체를 문서에 삽입할 수 있습니다. 이 유형에 대해 QTextObjectInterface도 구현되어야 하며 문서의 QAbstractTextDocumentLayout 과 함께 registered 여야 합니다. QTextDocument 을 렌더링하는 동안 객체 유형이 발생하면 인터페이스의 intrinsicSize() 및 drawObject() 함수가 호출됩니다.

다음 목록은 문서에 사용자 정의 텍스트 객체를 삽입하는 데 필요한 단계를 설명합니다:

텍스트 객체를 구현하는 클래스는 QObject 와 QTextObjectInterface 를 모두 상속해야 합니다. QObject 이 가장 먼저 상속되는 클래스여야 합니다. 예를 들어:

class SvgTextObject : public QObject, public QTextObjectInterface
{
    Q_OBJECT
    Q_INTERFACES(QTextObjectInterface)

텍스트 객체의 데이터는 일반적으로 QTextCharFormat::setProperty()을 사용하여 QTextCharFormat 에 저장한 다음 QTextCharFormat::property()로 검색합니다.

경고: 복사 및 붙여넣기 작업은 사용자 지정 텍스트 객체를 무시합니다.

QTextCharFormatQTextLayout참조하세요 .

멤버 함수 문서

[virtual noexcept] QTextObjectInterface::~QTextObjectInterface()

이것을 파괴합니다 QTextObjectInterface.

[pure virtual] void QTextObjectInterface::drawObject(QPainter *painter, const QRectF &rect, QTextDocument *doc, int posInDocument, const QTextFormat &format)

지정된 painter 을 사용하여 이 텍스트 객체를 그립니다.

그릴 직사각형의 크기 rect 는 이전에 intrinsicSize()로 계산한 크기입니다. 직사각형 위치는 painter 에 상대적입니다.

또한 해당 문서에서 문서(doc)와 format 의 위치(posInDocument)도 가져옵니다.

intrinsicSize()도 참조하세요 .

[pure virtual] QSizeF QTextObjectInterface::intrinsicSize(QTextDocument *doc, int posInDocument, const QTextFormat &format)

intrinsicSize() 함수는 지정된 문서(doc)에서 지정된 위치(posInDocument)에 있는 format 로 표시되는 텍스트 객체의 크기를 반환합니다.

계산된 크기는 이 format 에 대한 후속 drawObject() 호출에 사용됩니다.

drawObject()도 참조하세요 .

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