QPainterStateGuard Class
QPainterStateGuard は、QPainter::save() とQPainter::restore() 呼び出しのバランスをとるための RAII 便利クラスです。詳細...
ヘッダ | #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() が呼び出されるようにして、これら 2 つの関数間の呼び出しが不均衡にならないようにする必要があります。
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)
QPainterStateGuard を構築し、state がInitialState::Save
の場合(デフォルト)、painter でsave() を呼び出します。QPainterStateGuard が破棄されると、QPainter の状態を復元するためにsave() が呼び出されたのと同じ回数、restore() が呼び出されます。
[noexcept]
QPainterStateGuard::QPainterStateGuard(QPainterStateGuard &&other)
other 。
[noexcept]
QPainterStateGuard::~QPainterStateGuard()
QPainterStateGuard インスタンスを破棄し、save() が呼び出された回数だけrestore() を呼び出してQPainter の状態を復元する。
void QPainterStateGuard::restore()
内部セーブ/リストア・カウンタがゼロより大きい場合、QPainter::restore ()を呼び出す。
注意: この関数は、カウンタがすでにゼロに達している場合、デバッグ・ビルドでアサートする。
void QPainterStateGuard::save()
QPainter::save() を呼び出し、内部のセーブ/リストアカウンターを1増やす。
[noexcept]
void QPainterStateGuard::swap(QPainterStateGuard &other)
other をこのペインターのステートガードと入れ替える。この操作は非常に速く、失敗することはない。
[noexcept]
QPainterStateGuard &QPainterStateGuard::operator=(QPainterStateGuard &&other)
Move-このペインターのステートガードに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.