QGraphicsTextItem Class
QGraphicsTextItem 클래스는 서식이 지정된 텍스트를 표시하기 위해 QGraphics QGraphicsScene 에 추가할 수 있는 텍스트 항목을 제공합니다. 더 보기...
| 헤더: | #include <QGraphicsTextItem> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Widgets) target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
| qmake: | QT += widgets |
| 상속: | QGraphicsObject |
공개 유형
| enum { Type } |
속성
- openExternalLinks : bool
- textCursor : QTextCursor
공개 함수
| QGraphicsTextItem(QGraphicsItem *parent = nullptr) | |
| QGraphicsTextItem(const QString &text, QGraphicsItem *parent = nullptr) | |
| virtual | ~QGraphicsTextItem() |
| void | adjustSize() |
| QColor | defaultTextColor() const |
| QTextDocument * | document() const |
| QFont | font() const |
| bool | openExternalLinks() const |
| void | setDefaultTextColor(const QColor &col) |
| void | setDocument(QTextDocument *document) |
| void | setFont(const QFont &font) |
| void | setHtml(const QString &text) |
| void | setOpenExternalLinks(bool open) |
| void | setPlainText(const QString &text) |
| void | setTabChangesFocus(bool b) |
| void | setTextCursor(const QTextCursor &cursor) |
| void | setTextInteractionFlags(Qt::TextInteractionFlags flags) |
| void | setTextWidth(qreal width) |
| bool | tabChangesFocus() const |
| QTextCursor | textCursor() const |
| Qt::TextInteractionFlags | textInteractionFlags() const |
| qreal | textWidth() const |
| QString | toHtml() const |
| QString | toPlainText() const |
재구현된 공용 함수
| virtual QRectF | boundingRect() const override |
| virtual bool | contains(const QPointF &point) const override |
| virtual bool | isObscuredBy(const QGraphicsItem *item) const override |
| virtual QPainterPath | opaqueArea() const override |
| virtual void | paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override |
| virtual QPainterPath | shape() const override |
| virtual int | type() const override |
신호
| void | linkActivated(const QString &link) |
| void | linkHovered(const QString &link) |
재구현된 보호 함수
| virtual void | contextMenuEvent(QGraphicsSceneContextMenuEvent *event) override |
| virtual void | dragEnterEvent(QGraphicsSceneDragDropEvent *event) override |
| virtual void | dragLeaveEvent(QGraphicsSceneDragDropEvent *event) override |
| virtual void | dragMoveEvent(QGraphicsSceneDragDropEvent *event) override |
| virtual void | dropEvent(QGraphicsSceneDragDropEvent *event) override |
| virtual void | focusInEvent(QFocusEvent *event) override |
| virtual void | focusOutEvent(QFocusEvent *event) override |
| virtual void | hoverEnterEvent(QGraphicsSceneHoverEvent *event) override |
| virtual void | hoverLeaveEvent(QGraphicsSceneHoverEvent *event) override |
| virtual void | hoverMoveEvent(QGraphicsSceneHoverEvent *event) override |
| virtual void | inputMethodEvent(QInputMethodEvent *event) override |
| virtual QVariant | inputMethodQuery(Qt::InputMethodQuery query) const override |
| virtual void | keyPressEvent(QKeyEvent *event) override |
| virtual void | keyReleaseEvent(QKeyEvent *event) override |
| virtual void | mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) override |
| virtual void | mouseMoveEvent(QGraphicsSceneMouseEvent *event) override |
| virtual void | mousePressEvent(QGraphicsSceneMouseEvent *event) override |
| virtual void | mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override |
| virtual bool | sceneEvent(QEvent *event) override |
상세 설명
항목에 일반 텍스트만 표시해야 하는 경우, 대신 QGraphicsSimpleTextItem 를 사용하는 것을 고려해 보십시오.
항목의 텍스트를 설정하려면 QString 를 QGraphicsTextItem의 생성자에 전달하거나, setHtml()/setPlainText()를 호출하십시오.
QGraphicsTextItem은 텍스트의 서식 적용 후 크기와 관련 글꼴을 사용하여 boundingRect(), shape(), contains() 메서드를 적절하게 구현합니다. setFont()을 호출하여 글꼴을 설정할 수 있습니다.
setTextInteractionFlags()를 사용하여 Qt::TextEditorInteraction 플래그를 설정하면 항목을 편집 가능하게 만들 수 있습니다.
항목의 권장 텍스트 너비는 setTextWidth()를 사용하여 설정할 수 있으며, textWidth()를 사용하여 확인할 수 있습니다.
참고: HTML 텍스트를 중앙정렬하려면 항목의 텍스트 너비를 설정해야 합니다. 그렇지 않은 경우, 항목의 텍스트를 설정한 후 adjustSize()를 호출할 수 있습니다.

참고: QGraphicsTextItem은 기본적으로 hover events 을 허용합니다. setAcceptHoverEvents()을 사용하여 이 설정을 변경할 수 있습니다.
참조: QGraphicsSimpleTextItem, QGraphicsPathItem, QGraphicsRectItem, QGraphicsEllipseItem, QGraphicsPixmapItem, QGraphicsPolygonItem, QGraphicsLineItem 및 Graphics View Framework.
속성 설명
openExternalLinks : bool
QGraphicsTextItem 가 linkActivated 신호를 발생시키는 대신 QDesktopServices::openUrl()을 사용하여 링크를 자동으로 열어야 하는지 여부를 지정합니다.
기본값은 false입니다.
액세스 함수:
| bool | openExternalLinks() const |
| void | setOpenExternalLinks(bool open) |
textCursor : QTextCursor
이 속성은 편집 가능한 텍스트 항목에서 표시되는 텍스트 커서를 나타냅니다.
기본적으로 항목의 텍스트가 설정되지 않은 경우, 이 속성은 빈 텍스트 커서를 포함하며, 그렇지 않은 경우 항목 문서의 시작 부분에 위치한 텍스트 커서를 포함합니다.
액세스 함수:
| QTextCursor | textCursor() const |
| void | setTextCursor(const QTextCursor &cursor) |
멤버 함수 설명서
[explicit] QGraphicsTextItem::QGraphicsTextItem(QGraphicsItem *parent = nullptr)
QGraphicsTextItem 객체를 생성합니다. ` parent `는 ` QGraphicsItem`의 생성자에 전달됩니다.
QGraphicsScene::addItem()도 참조하십시오 .
[explicit] QGraphicsTextItem::QGraphicsTextItem(const QString &text, QGraphicsItem *parent = nullptr)
text 를 기본 일반 텍스트로 사용하여 QGraphicsTextItem을 생성합니다. parent 는 QGraphicsItem 의 생성자에 전달됩니다.
QGraphicsScene::addItem()도 참조하십시오 .
[virtual noexcept] QGraphicsTextItem::~QGraphicsTextItem()
QGraphicsTextItem 를 삭제합니다.
void QGraphicsTextItem::adjustSize()
텍스트 항목을 적당한 크기로 조정합니다.
[override virtual] QRectF QGraphicsTextItem::boundingRect() const
QGraphicsItem::boundingRect() const를 재구현합니다.
[override virtual] bool QGraphicsTextItem::contains(const QPointF &point) const
QGraphicsItem::contains(const QPointF &point) const를 재구현합니다.
[override virtual protected] void QGraphicsTextItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
QGraphicsItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)를 재구현합니다.
QColor QGraphicsTextItem::defaultTextColor() const
서식이 적용되지 않은 텍스트에 사용되는 기본 텍스트 색상을 반환합니다.
setDefaultTextColor()도 참조하십시오 .
QTextDocument *QGraphicsTextItem::document() const
항목의 텍스트 문서를 반환합니다.
setDocument()도 참조하십시오 .
[override virtual protected] void QGraphicsTextItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)
QGraphicsItem::dragEnterEvent(QGraphicsSceneDragDropEvent *event)를 재구현합니다.
[override virtual protected] void QGraphicsTextItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)
QGraphicsItem::dragLeaveEvent(QGraphicsSceneDragDropEvent *event)를 재구현합니다.
[override virtual protected] void QGraphicsTextItem::dragMoveEvent(QGraphicsSceneDragDropEvent *event)
QGraphicsItem::dragMoveEvent(QGraphicsSceneDragDropEvent *event)를 재구현합니다.
[override virtual protected] void QGraphicsTextItem::dropEvent(QGraphicsSceneDragDropEvent *event)
QGraphicsItem::dropEvent(QGraphicsSceneDragDropEvent *event)를 재구현합니다.
[override virtual protected] void QGraphicsTextItem::focusInEvent(QFocusEvent *event)
QGraphicsItem::focusInEvent(QFocusEvent *event)를 재구현합니다.
[override virtual protected] void QGraphicsTextItem::focusOutEvent(QFocusEvent *event)
QGraphicsItem::focusOutEvent(QFocusEvent *event)를 재구현합니다.
QFont QGraphicsTextItem::font() const
텍스트를 렌더링하는 데 사용되는 항목의 글꼴을 반환합니다.
setFont()도 참조하십시오 .
[override virtual protected] void QGraphicsTextItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
QGraphicsItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)을 재구현합니다.
[override virtual protected] void QGraphicsTextItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
QGraphicsItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event)를 재구현합니다.
[override virtual protected] void QGraphicsTextItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)
QGraphicsItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event)를 재구현합니다.
[override virtual protected] void QGraphicsTextItem::inputMethodEvent(QInputMethodEvent *event)
QGraphicsItem::inputMethodEvent(QInputMethodEvent *event)를 재구현합니다.
[override virtual protected] QVariant QGraphicsTextItem::inputMethodQuery(Qt::InputMethodQuery query) const
QGraphicsItem::inputMethodQuery(const Qt::InputMethodQuery query)를 재구현합니다.
[override virtual] bool QGraphicsTextItem::isObscuredBy(const QGraphicsItem *item) const
QGraphicsItem::isObscuredBy(const QGraphicsItem *item) const를 재구현합니다.
[override virtual protected] void QGraphicsTextItem::keyPressEvent(QKeyEvent *event)
QGraphicsItem::keyPressEvent(QKeyEvent *event)를 재구현합니다.
[override virtual protected] void QGraphicsTextItem::keyReleaseEvent(QKeyEvent *event)
QGraphicsItem::keyReleaseEvent(QKeyEvent *event)를 재구현합니다.
[signal] void QGraphicsTextItem::linkActivated(const QString &link)
이 신호는 사용자가 Qt::LinksAccessibleByMouse 또는 Qt::LinksAccessibleByKeyboard 를 활성화하는 텍스트 항목의 링크를 클릭할 때 발생합니다. link 는 클릭된 링크입니다.
setTextInteractionFlags()도 참조하십시오 .
[signal] void QGraphicsTextItem::linkHovered(const QString &link)
이 신호는 사용자가 Qt::LinksAccessibleByMouse 기능을 지원하는 텍스트 항목의 링크 위에 마우스를 올렸을 때 발생합니다. link 는 마우스를 올린 링크입니다.
setTextInteractionFlags()도 참조하십시오 .
[override virtual protected] void QGraphicsTextItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
QGraphicsItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)를 재구현합니다.
[override virtual protected] void QGraphicsTextItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
QGraphicsItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)를 재구현합니다.
[override virtual protected] void QGraphicsTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
QGraphicsItem::mousePressEvent(QGraphicsSceneMouseEvent *event)을 재구현합니다.
[override virtual protected] void QGraphicsTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
QGraphicsItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)를 재구현합니다.
[override virtual] QPainterPath QGraphicsTextItem::opaqueArea() const
QGraphicsItem::opaqueArea() const를 재구현합니다.
[override virtual] void QGraphicsTextItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
QGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)을 재구현합니다.
[override virtual protected] bool QGraphicsTextItem::sceneEvent(QEvent *event)
QGraphicsItem::sceneEvent(QEvent *event)를 재구현합니다.
void QGraphicsTextItem::setDefaultTextColor(const QColor &col)
서식이 적용되지 않은 텍스트의 색상을 col 로 설정합니다.
defaultTextColor()도 참조하십시오 .
void QGraphicsTextItem::setDocument(QTextDocument *document)
항목에 텍스트 문서 document 를 설정합니다.
document()도 참조하십시오 .
void QGraphicsTextItem::setFont(const QFont &font)
텍스트 항목을 렌더링하는 데 사용되는 글꼴을 ‘ font ’로 설정합니다.
font()도 참조하십시오 .
void QGraphicsTextItem::setHtml(const QString &text)
항목의 텍스트를 text 로 설정하며, 해당 텍스트가 HTML 형식으로 되어 있다고 가정합니다. 항목에 키보드 입력 포커스가 있는 경우, 이 함수는 ensureVisible()도 호출하여 모든 뷰포트에서 텍스트가 표시되도록 합니다.
toHtml(), hasFocus() 및 QGraphicsSimpleTextItem도 참조하십시오 .
void QGraphicsTextItem::setPlainText(const QString &text)
항목의 텍스트를 ‘ text ’로 설정합니다. 항목에 키보드 입력 포커스가 있는 경우, 이 함수는 ensureVisible()도 호출하여 모든 뷰포트에서 텍스트가 표시되도록 합니다.
toHtml() 및 hasFocus()도 참조하십시오 .
void QGraphicsTextItem::setTabChangesFocus(bool b)
b 가 true인 경우, Tab 키를 누르면 위젯의 포커스가 이동합니다. 그렇지 않은 경우, Tab 키를 누르면 문서에 탭이 삽입됩니다.
경우에 따라 텍스트 편집 시 사용자가 탭 키( Tab )를 사용하여 탭을 입력하거나 들여쓰기를 변경하는 것을 허용해서는 안 됩니다. 이는 포커스 체인을 끊어버리기 때문입니다. 기본값은 false입니다.
tabChangesFocus(), ItemIsFocusable 및 textInteractionFlags()도 참조하십시오 .
void QGraphicsTextItem::setTextInteractionFlags(Qt::TextInteractionFlags flags)
flags 플래그를 설정하여 텍스트 항목이 사용자 입력에 어떻게 반응할지 지정합니다.
QGraphicsTextItem 의 기본값은 Qt::NoTextInteraction 입니다. 이 함수는 또한 flags 가 Qt::NoTextInteraction 와 다를 경우 QGraphicsItem 플래그를 설정하고, 그렇지 않을 경우 해당 플래그를 지움으로써 ItemIsFocusable 플래그에도 영향을 미칩니다.
기본적으로 텍스트는 읽기 전용입니다. 항목을 편집기로 변환하려면 Qt::TextEditable 플래그를 설정하십시오.
textInteractionFlags()함수도 참조하십시오 .
void QGraphicsTextItem::setTextWidth(qreal width)
항목 텍스트의 권장 너비를 설정합니다. 실제 텍스트의 너비가 지정된 너비보다 넓을 경우, 여러 줄로 나누어 표시됩니다.
width 가 -1로 설정된 경우, 명시적인 줄 바꿈이나 새 단락을 통해 강제로 줄 바꿈이 이루어지지 않는 한 텍스트가 여러 줄로 나뉘지 않습니다.
기본값은 -1입니다.
QGraphicsTextItem 는 내부적으로 텍스트 너비를 계산하는 데 사용되는 ` QTextDocument `를 유지한다는 점에 유의하십시오.
textWidth() 및 QTextDocument::setTextWidth()도 참조하십시오 .
[override virtual] QPainterPath QGraphicsTextItem::shape() const
QGraphicsItem::shape() const를 재구현합니다.
bool QGraphicsTextItem::tabChangesFocus() const
Tab 키가 위젯의 포커스를 변경하게 되는 경우 ` true `를 반환하고, 그렇지 않은 경우 `false`를 반환합니다.
기본적으로 이 동작은 비활성화되어 있으며, 이 함수는 false를 반환합니다.
setTabChangesFocus()도 참조하십시오 .
Qt::TextInteractionFlags QGraphicsTextItem::textInteractionFlags() const
현재 텍스트 상호작용 플래그를 반환합니다.
setTextInteractionFlags()도 참조하십시오 .
qreal QGraphicsTextItem::textWidth() const
텍스트의 너비를 반환합니다.
너비는 QGraphicsTextItem 가 내부적으로 유지하는 QTextDocument 를 사용하여 계산됩니다.
setTextWidth() 및 QTextDocument::textWidth()도 참조하십시오 .
QString QGraphicsTextItem::toHtml() const
항목의 텍스트를 HTML 형식으로 변환한 결과를 반환하거나, 텍스트가 설정되지 않은 경우 빈 QString 객체를 반환합니다.
setHtml()도 참조하십시오 .
QString QGraphicsTextItem::toPlainText() const
항목의 텍스트를 일반 텍스트로 변환한 값을 반환하거나, 텍스트가 설정되지 않은 경우 빈 QString 객체를 반환합니다.
setPlainText()도 참조하십시오 .
[override virtual] int QGraphicsTextItem::type() const
QGraphicsItem::type() const를 재구현합니다.
© 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.