The QStylePainter class is a convenience class for drawing QStyle 元素在 Widget 內。 更多...
| 頭: | #include <QStylePainter> |
| 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 = ...) |
| void | drawPrimitive (QStyle::PrimitiveElement pe , const QStyleOption & option ) |
| QStyle * | style () const |
The QStylePainter class is a convenience class for drawing QStyle 元素在 Widget 內。
QStylePainter
extends
QPainter
采用一組高級
draw...()
函數實現基於
QStyle
's API. The advantage of using
QStylePainter
is that the parameter lists get considerably shorter. Whereas a
QStyle
對象能夠在任何 Widget 中繪製必須使用任何描繪器 (因為應用程序通常有一
QStyle
object shared by all widget), a
QStylePainter
is initialized with a widget, eliminating the need to specify the
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 .
構造 QStylePainter using widget widget 對於其描繪設備。
構造 QStylePainter 使用 pd 對於其描繪設備,且屬性來自 widget .
開始描繪操作在指定
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 .