이 페이지에서

QStylePainter Class

QStylePainter 클래스는 위젯 내부에서 Q QStyle 요소를 그리는 데 사용되는 편의 클래스입니다. 더 보기...

헤더: #include <QStylePainter>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets
상속: QPainter

공개 함수

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는 QStyle 의 API를 기반으로 구현된 일련의 고수준 draw...() 함수를 통해 QPainter 를 확장합니다. QStylePainter를 사용하면 매개변수 목록이 상당히 짧아진다는 장점이 있습니다. QStyle 객체는 어떤 페인터를 사용하든 모든 위젯에 그릴 수 있어야 하는 반면(일반적으로 애플리케이션에는 모든 위젯이 공유하는 하나의 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)

직사각형 rect 과 팔레트 pal 을 사용하여 ‘ text ’을 그립니다. 텍스트는 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.