QStylePainter Class
QStylePainter クラスは、ウィジェット内にQStyle 要素を描画するための利便性向上のためのクラスです。詳細...
| ヘッダー: | #include <QStylePainter> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Widgets) target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
| qmake: | QT += widgets |
| 継承元: | QPainter |
- 継承されたメンバーを含むすべてのメンバーの一覧
- QStylePainterは、ペイントクラスの一部です。
パブリック関数
| QStylePainter() | |
| QStylePainter(QWidget *widget) | |
| QStylePainter(QPaintDevice *pd, QWidget *widget) | |
| bool | begin(QWidget *widget) |
| bool | begin(QPaintDevice *pd, QWidget *widget) |
| void | drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex &option) |
| void | drawControl(QStyle::ControlElement ce, const QStyleOption &option) |
| void | drawItemPixmap(const QRect &rect, int flags, const QPixmap &pixmap) |
| void | drawItemText(const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole = QPalette::NoRole) |
| void | drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption &option) |
| QStyle * | style() const |
詳細な説明
QStylePainterは、QPainter を拡張し、QStyle のAPIの上に実装された一連の高レベルなdraw...() 関数を提供します。QStylePainterを使用する利点は、パラメータリストが大幅に短くなることです。QStyle オブジェクトは、任意のペインターを使用して任意のウィジェットに描画できる必要があります(通常、アプリケーションにはすべてのウィジェットで共有される1つのQStyle オブジェクトがあるため)。一方、QStylePainterはウィジェットとともに初期化されるため、関数呼び出しのたびにQWidget 、QPainter 、QStyle を指定する必要がなくなります。
QStyle を直接使用する例:
void MyWidget::paintEvent(QPaintEvent * /* event */)
{
QPainter painter(this);
QStyleOptionFocusRect option;
option.initFrom(this);
option.backgroundColor = palette().color(QPalette::Window);
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this);
}QStylePainter を使用する例:
void MyWidget::paintEvent(QPaintEvent * /* event */)
{
QStylePainter painter(this);
QStyleOptionFocusRect option;
option.initFrom(this);
option.backgroundColor = palette().color(QPalette::Window);
painter.drawPrimitive(QStyle::PE_FrameFocusRect, option);
}QStyle およびQStyleOptionも参照してください 。
メンバ関数のドキュメント
QStylePainter::QStylePainter()
QStylePainter を作成します。
[explicit] QStylePainter::QStylePainter(QWidget *widget)
ペイントデバイスとしてウィジェット `widget ` を使用する `QStylePainter` を構築します。
QStylePainter::QStylePainter(QPaintDevice *pd, QWidget *widget)
pd をペイントデバイスとして、またwidget の属性を用いて、QStylePainter を作成します。
bool QStylePainter::begin(QWidget *widget)
指定されたwidget での描画処理を開始します。ペインターが使用可能な状態であればtrue を返し、そうでない場合はfalse を返します。
これは、QWidget を受け取るコンストラクタによって自動的に呼び出されます。
bool QStylePainter::begin(QPaintDevice *pd, QWidget *widget)
ペイントデバイス `pd ` に対して、あたかもそれが `widget` であるかのように、ペイント処理を開始します。
これは、QPaintDevice とQWidget を引数とするコンストラクタによって自動的に呼び出されます。
これはオーバーロードされた関数です。
void QStylePainter::drawComplexControl(QStyle::ComplexControl cc, const QStyleOptionComplex &option)
QStyleOptionComplex option で指定された複雑なコントロールcc を、ウィジェットのスタイルを使用して描画します。
QStyle::drawComplexControl()も参照してください 。
void QStylePainter::drawControl(QStyle::ControlElement ce, const QStyleOption &option)
ウィジェットのスタイルを使用して、QStyleOption option で指定されたコントロール要素ce を描画します。
QStyle::drawControl()も参照してください 。
void QStylePainter::drawItemPixmap(const QRect &rect, int flags, const QPixmap &pixmap)
矩形rect 内にpixmap を描画します。ピクマップはflags に従って配置されます。
QStyle::drawItemPixmap() およびQt::Alignmentも参照してください 。
void QStylePainter::drawItemText(const QRect &rect, int flags, const QPalette &pal, bool enabled, const QString &text, QPalette::ColorRole textRole = QPalette::NoRole)
text を、矩形rect およびパレットpal 内に描画します。テキストは、flags に従って配置および改行されます。
ペンの色は `textRole` で指定されます。`enabled ` のブール値は、アイテムが有効かどうかを示します。これを再実装する際、このブール値はアイテムの描画方法に影響を与えるようにする必要があります。
QStyle::drawItemText() およびQt::Alignmentも参照してください 。
void QStylePainter::drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption &option)
ウィジェットのスタイルを使用して、QStyleOption option で指定されたプリミティブ要素pe を描画します。
QStyle::drawPrimitive()も参照してください 。
QStyle *QStylePainter::style() const
QStylePainter で現在使用されているスタイルを返します。
© 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.