QPainterStateGuard Class
QPainterStateGuard는 균형 잡힌 QPainter::save() 및 QPainter::restore() 호출을 위한 RAII 편의 클래스입니다. 더 보기...
Header: | #include <QPainterStateGuard> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui) |
qmake: | QT += gui |
이후: | Qt 6.9 |
- 상속된 멤버를 포함한 모든 멤버의 목록
- QPainterStateGuard는 페인팅 클래스의 일부입니다.
참고: 이 클래스의 모든 함수는 재진입합니다.
공용 함수
QPainterStateGuard(QPainter *painter, QPainterStateGuard::InitialState state = InitialState::Save) | |
QPainterStateGuard(QPainterStateGuard &&other) | |
~QPainterStateGuard() | |
void | restore() |
void | save() |
void | swap(QPainterStateGuard &other) |
QPainterStateGuard & | operator=(QPainterStateGuard &&other) |
상세 설명
두 함수 간의 호출 불균형을 피하기 위해 QPainterStateGuard는 모든 곳에서 QPainter::save()를 대체하여 페인팅 루틴이 끝나면 해당 QPainter::restore()가 호출되도록 해야 합니다.
QPainter::save()/QPainter::restore()를 사용한 예시:
void MyWidget::paintEvent(QPaintEvent *) { QPainter painter(this); painter.setPen(Qt::red); if (drawText) { painter.save(); painter.setPen(Qt::blue); painter.setFont(QFont("Arial", 30)); painter.drawText(rect(), Qt::AlignCenter, "Qt"); painter.restore(); // don't forget to restore previous painter state } painter.drawLine(line); }
QPainterStateGuard를 사용한 예제:
void MyGuardWidget::paintEvent(QPaintEvent *) { QPainter painter(this); painter.setPen(Qt::red); if (drawText) { QPainterStateGuard guard(&painter) painter.setPen(Qt::blue); painter.setFont(QFont("Arial", 30)); painter.drawText(rect(), Qt::AlignCenter, "Qt"); } painter.drawLine(line); }
QPainter 를참조하십시오 .
멤버 함수 문서
[explicit]
QPainterStateGuard::QPainterStateGuard(QPainter *painter, QPainterStateGuard::InitialState state = InitialState::Save)
state 가 InitialState::Save
(기본값인 경우)인 경우 painter 에서 save()를 호출하여 QPainterStateGuard를 생성합니다. QPainterStateGuard가 소멸되면 save()가 호출된 횟수만큼 restore()가 호출되어 QPainter 의 상태를 복원합니다.
[noexcept]
QPainterStateGuard::QPainterStateGuard(QPainterStateGuard &&other)
이동 - other 에서 페인터 상태 가드를 구성합니다.
[noexcept]
QPainterStateGuard::~QPainterStateGuard()
QPainterStateGuard 인스턴스를 파괴하고 save()를 호출한 횟수만큼 restore()를 호출하여 QPainter 의 상태를 복원합니다.
void QPainterStateGuard::restore()
내부 저장/복원 카운터가 0보다 크면 QPainter::restore()를 호출합니다.
참고: 이 함수는 카운터가 이미 0에 도달한 경우 디버그 빌드에서 어설트됩니다.
void QPainterStateGuard::save()
QPainter::save()를 호출하고 내부 저장/복원 카운터를 1 증가시킵니다.
[noexcept]
void QPainterStateGuard::swap(QPainterStateGuard &other)
other 를 이 페인터 상태 가드로 바꿉니다. 이 작업은 매우 빠르며 실패하지 않습니다.
[noexcept]
QPainterStateGuard &QPainterStateGuard::operator=(QPainterStateGuard &&other)
이동-이 페인터 상태 가드에 other 을 할당합니다.
© 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.