QStylePainter 類是方便類用於繪製 QStyle 元素在 Widget 內。 更多...
| 頭: | #include <QStylePainter> |
| qmake: | QT += widgets |
| 繼承: | QPainter |
| QStylePainter (QPaintDevice * pd , QWidget * widget ) | |
| QStylePainter (QWidget * widget ) | |
| QStylePainter () | |
| 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
采用一組高級
draw...()
函數實現基於
QStyle
的 API。使用 QStylePainter 的優點是參數列錶會變得相當短。而
QStyle
對象能夠在任何 Widget 中繪製必須使用任何描繪器 (因為應用程序通常有一
QStyle
對象由所有 Widget 共享),QStylePainter 采用 Widget 初始化,無需指定
QWidget
,
QPainter
,和
QStyle
對於每個函數調用。
範例使用 QStyle 直接:
void MyWidget::paintEvent(QPaintEvent * /* event */) { QPainter painter(this); QStyleOptionFocusRect option; option.initFrom(this); option.backgroundColor = palette().color(QPalette::Background); 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::Background); painter.drawPrimitive(QStyle::PE_FrameFocusRect, option); }
另請參閱 QStyle and QStyleOption .
構造 QStylePainter 使用 pd 對於其描繪設備,且屬性來自 widget .
構造 QStylePainter 使用小部件 widget 對於其描繪設備。
構造 QStylePainter。
開始描繪操作在指定
widget
。返迴
true
若描繪器使用就緒;否則返迴
false
.
這被自動調用通過構造函數接受 QWidget .
這是重載函數。
開始描繪操作在描繪設備 pd 就像它是 widget .
這被自動調用通過構造函數接受 QPaintDevice 和 QWidget .
使用 Widget 的樣式來繪製復雜控件 cc 指定通過 QStyleOptionComplex option .
另請參閱 QStyle::drawComplexControl ().
使用 Widget 的樣式來繪製控件元素 ce 指定通過 QStyleOption option .
另請參閱 QStyle::drawControl ().
繪製 pixmap 按矩形 rect 。像素圖的對齊是根據 flags .
另請參閱 QStyle::drawItemPixmap () 和 Qt::Alignment .
繪製 text 按矩形 rect 和調色闆 pal 。文本的對齊和換行是根據 flags .
鋼筆顔色的指定是采用 textRole 。 enabled 布爾指示是否啓用項;當重實現此布爾時,應該會影響如何繪製項。
另請參閱 QStyle::drawItemText () 和 Qt::Alignment .
使用 Widget 樣式繪製圖元元素 pe 指定通過 QStyleOption option .
另請參閱 QStyle::drawPrimitive ().
返迴的當前樣式用於 QStylePainter .