void ColorButton::drawButton(QPainter *p) { QStyleOptionButton buttonOptions; buttonOptions.init(this); buttonOptions.features = QStyleOptionButton::None; buttonOptions.rect = rect(); buttonOptions.palette = palette(); buttonOptions.state = (isDown() ? QStyle::State_Sunken : QStyle::State_Raised); if (!mIsFlat) { style()->drawPrimitive(QStyle::PE_PanelButtonBevel, &buttonOptions, p, this); } else { style()->drawPrimitive(QStyle::PE_FrameDefaultButton, &buttonOptions, p, this); } p->save(); drawButtonLabel(p); p->restore(); QStyleOptionFocusRect frectOptions; frectOptions.init(this); frectOptions.rect = style()->subElementRect(QStyle::SE_PushButtonFocusRect, &buttonOptions, this); if (hasFocus()) { style()->drawPrimitive(QStyle::PE_FrameFocusRect, &frectOptions, p, this); } }
//! Draw a focus rectangle on a widget using its style. void QwtPainter::drawFocusRect( QPainter *painter, const QWidget *widget, const QRect &rect ) { QStyleOptionFocusRect opt; opt.init( widget ); opt.rect = rect; opt.state |= QStyle::State_HasFocus; widget->style()->drawPrimitive( QStyle::PE_FrameFocusRect, &opt, painter, widget ); }
void QwtPainter::drawFocusRect(QPainter *painter, QWidget *widget, const QRect &rect) { #if QT_VERSION < 0x040000 widget->style().drawPrimitive(QStyle::PE_FocusRect, painter, rect, widget->colorGroup()); #else QStyleOptionFocusRect opt; opt.init(widget); opt.rect = rect; opt.state |= QStyle::State_HasFocus; widget->style()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, painter, widget); #endif }
void ColorButton::paintEvent( QPaintEvent * ) { QPainter painter(this); //First, we need to draw the bevel. QStyleOptionButton butOpt; initStyleOption(&butOpt); style()->drawControl( QStyle::CE_PushButtonBevel, &butOpt, &painter, this ); //OK, now we can muck around with drawing out pretty little color box //First, sort out where it goes QRect labelRect = style()->subElementRect( QStyle::SE_PushButtonContents, &butOpt, this ); int shift = style()->pixelMetric( QStyle::PM_ButtonMargin ); labelRect.adjust(shift, shift, -shift, -shift); int x, y, w, h; labelRect.getRect(&x, &y, &w, &h); if (isChecked() || isDown()) { x += style()->pixelMetric( QStyle::PM_ButtonShiftHorizontal ); y += style()->pixelMetric( QStyle::PM_ButtonShiftVertical ); } QColor fillCol = isEnabled() ? btnColor : palette().color(backgroundRole()); qDrawShadePanel( &painter, x, y, w, h, palette(), true, 1, NULL); if ( fillCol.isValid() ) painter.fillRect( x+1, y+1, w-2, h-2, fillCol ); if ( hasFocus() ) { QRect focusRect = style()->subElementRect( QStyle::SE_PushButtonFocusRect, &butOpt, this ); QStyleOptionFocusRect focusOpt; focusOpt.init(this); focusOpt.rect = focusRect; focusOpt.backgroundColor = palette().background().color(); style()->drawPrimitive( QStyle::PE_FrameFocusRect, &focusOpt, &painter, this ); } }
void Q3GroupBox::drawFrame(QPainter *p) { QPoint p1, p2; QStyleOptionFrame opt; opt.init(this); int frameShape = d->frameStyle & QFrame::Shape_Mask; int frameShadow = d->frameStyle & QFrame::Shadow_Mask; int lw = 0; int mlw = 0; opt.rect = frameRect(); switch (frameShape) { case QFrame::Box: case QFrame::HLine: case QFrame::VLine: case QFrame::StyledPanel: lw = d->lineWidth; mlw = d->midLineWidth; break; default: // most frame styles do not handle customized line and midline widths // (see updateFrameWidth()). lw = d->frameWidth; break; } opt.lineWidth = lw; opt.midLineWidth = mlw; if (frameShadow == Sunken) opt.state |= QStyle::State_Sunken; else if (frameShadow == Raised) opt.state |= QStyle::State_Raised; switch (frameShape) { case Box: if (frameShadow == Plain) qDrawPlainRect(p, opt.rect, opt.palette.foreground().color(), lw); else qDrawShadeRect(p, opt.rect, opt.palette, frameShadow == Sunken, lw, mlw); break; case StyledPanel: style()->drawPrimitive(QStyle::PE_Frame, &opt, p, this); break; case Panel: if (frameShadow == Plain) qDrawPlainRect(p, opt.rect, opt.palette.foreground().color(), lw); else qDrawShadePanel(p, opt.rect, opt.palette, frameShadow == Sunken, lw); break; case WinPanel: if (frameShadow == Plain) qDrawPlainRect(p, opt.rect, opt.palette.foreground().color(), lw); else qDrawWinPanel(p, opt.rect, opt.palette, frameShadow == Sunken); break; case HLine: case VLine: if (frameShape == HLine) { p1 = QPoint(opt.rect.x(), opt.rect.height() / 2); p2 = QPoint(opt.rect.x() + opt.rect.width(), p1.y()); } else { p1 = QPoint(opt.rect.x()+opt.rect.width() / 2, 0); p2 = QPoint(p1.x(), opt.rect.height()); } if (frameShadow == Plain) { QPen oldPen = p->pen(); p->setPen(QPen(opt.palette.foreground().color(), lw)); p->drawLine(p1, p2); p->setPen(oldPen); } else { qDrawShadeLine(p, p1, p2, opt.palette, frameShadow == Sunken, lw, mlw); } break; } #ifdef QT_KEYPAD_NAVIGATION if (QApplication::keypadNavigationEnabled() && hasFocus()) { QStyleOptionFocusRect fopt; fopt.init(this); fopt.state |= QStyle::State_KeyboardFocusChange; fopt.rect = frameRect(); style()->drawPrimitive(QStyle::PE_FrameFocusRect, &fopt, p, this); } #endif }
/*! \brief Draw the button label \sa The Qt Manual on QPushButton */ void QwtArrowButton::drawButtonLabel(QPainter *p) { const bool isVertical = d_data->arrowType == Qt::UpArrow || d_data->arrowType == Qt::DownArrow; const QRect r = labelRect(); QSize boundingSize = labelRect().size(); if ( isVertical ) boundingSize.transpose(); const int w = (boundingSize.width() - (MaxNum - 1) * Spacing) / MaxNum; QSize arrow = arrowSize(Qt::RightArrow, QSize(w, boundingSize.height())); if ( isVertical ) arrow.transpose(); QRect contentsSize; // aligned rect where to paint all arrows if ( d_data->arrowType == Qt::LeftArrow || d_data->arrowType == Qt::RightArrow ) { contentsSize.setWidth(d_data->num * arrow.width() + (d_data->num - 1) * Spacing); contentsSize.setHeight(arrow.height()); } else { contentsSize.setWidth(arrow.width()); contentsSize.setHeight(d_data->num * arrow.height() + (d_data->num - 1) * Spacing); } QRect arrowRect(contentsSize); arrowRect.moveCenter(r.center()); arrowRect.setSize(arrow); p->save(); for (int i = 0; i < d_data->num; i++) { drawArrow(p, arrowRect, d_data->arrowType); int dx = 0; int dy = 0; if ( isVertical ) dy = arrow.height() + Spacing; else dx = arrow.width() + Spacing; #if QT_VERSION >= 0x040000 arrowRect.translate(dx, dy); #else arrowRect.moveBy(dx, dy); #endif } p->restore(); if ( hasFocus() ) { #if QT_VERSION >= 0x040000 QStyleOptionFocusRect option; option.init(this); option.backgroundColor = palette().color(QPalette::Background); style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, p, this); #else const QRect focusRect = style().subRect(QStyle::SR_PushButtonFocusRect, this); style().drawPrimitive(QStyle::PE_FocusRect, p, focusRect, colorGroup()); #endif } }