void NorwegianWoodStyle::polish(QPalette &palette) { QColor brown(212, 140, 95); QColor beige(212, 140, 95); QColor slightlyOpaqueBlack(0, 0, 0, 63); QPixmap backgroundIamge(":/images/woodbackground.png"); QPixmap buttonImage(":/images/woodbutton.png"); QPixmap midImage = buttonImage; QPainter painter; painter.begin(&midImage); painter.setPen(Qt::NoPen); painter.fillRect(midImage.rect(), slightlyOpaqueBlack); painter.end(); palette = QPalette(brown); palette.setBrush(QPalette::BrightText, Qt::white); palette.setBrush(QPalette::Base, beige); palette.setBrush(QPalette::Highlight, Qt::darkGreen); setTexture(palette, QPalette::Button, buttonImage); setTexture(palette, QPalette::Mid, midImage); setTexture(palette, QPalette::Window, backgroundIamge); QBrush brush = palette.background(); brush.setColor(brush.color().dark()); palette.setBrush(QPalette::Disabled, QPalette::WindowText, brush); palette.setBrush(QPalette::Disabled, QPalette::Text, brush); palette.setBrush(QPalette::Disabled, QPalette::ButtonText, brush); palette.setBrush(QPalette::Disabled, QPalette::Base, brush); palette.setBrush(QPalette::Disabled, QPalette::Button, brush); palette.setBrush(QPalette::Disabled, QPalette::Mid, brush); }
void CustomStyle::polish(QPalette &palette) { QColor brown(Qt::white); QColor beige(Qt::transparent); QColor slightlyOpaqueBlack(0, 0, 0, 63); // QPainter painter; // painter.begin(&midImage); // painter.setPen(Qt::NoPen); // painter.fillRect(midImage.rect(), slightlyOpaqueBlack); // painter.end(); palette = QPalette(brown); palette.setBrush(QPalette::BrightText, Qt::white); palette.setBrush(QPalette::Base, beige); palette.setBrush(QPalette::Highlight, Qt::darkGreen); palette.setBrush(QPalette::Button, beige); palette.setBrush(QPalette::ButtonText, Qt::white); palette.setBrush(QPalette::Mid, beige); // palette.setBrush(QPalette::Window, QColor(158, 202, 243)); palette.setBrush(QPalette::Window, beige); QBrush brush = palette.background(); brush.setColor(brush.color().dark()); palette.setBrush(QPalette::Disabled, QPalette::WindowText, brush); palette.setBrush(QPalette::Disabled, QPalette::Text, brush); palette.setBrush(QPalette::Disabled, QPalette::ButtonText, Qt::gray); palette.setBrush(QPalette::Disabled, QPalette::Base, brush); palette.setBrush(QPalette::Disabled, QPalette::Button, brush); palette.setBrush(QPalette::Disabled, QPalette::Mid, brush); }
void QMdStyle::drawBronzeBevel(const QStyleOption *option, QPainter *painter) const { QColor buttonColor = option->palette.button().color(); int coeff = (option->state & State_MouseOver) ? 115 : 105; QLinearGradient gradient(0, 0, 0, option->rect.height()); gradient.setColorAt(0.0, option->palette.light().color()); gradient.setColorAt(0.2, buttonColor.lighter(coeff)); gradient.setColorAt(0.8, buttonColor.darker(coeff)); gradient.setColorAt(1.0, option->palette.dark().color()); double penWidth = 1.0; if (const QStyleOptionButton *buttonOpt = qstyleoption_cast<const QStyleOptionButton *>(option)) { if (buttonOpt->features & QStyleOptionButton::DefaultButton) penWidth = 2.0; } QRect roundRect = option->rect.adjusted(+1, +1, -1, -1); if (!roundRect.isValid()) return; int diameter = 12; int cx = 100 * diameter / roundRect.width(); int cy = 100 * diameter / roundRect.height(); painter->save(); painter->setPen(Qt::NoPen); painter->setBrush(gradient); painter->drawRoundRect(roundRect, cx, cy); if (option->state & (State_On | State_Sunken)) { QColor slightlyOpaqueBlack(0, 0, 0, 63); painter->setBrush(slightlyOpaqueBlack); painter->drawRoundRect(roundRect, cx, cy); } painter->setRenderHint(QPainter::Antialiasing, true); painter->setPen(QPen(option->palette.foreground(), penWidth)); painter->setBrush(Qt::NoBrush); painter->drawRoundRect(roundRect, cx, cy); painter->restore(); }
void NorwegianWoodStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { switch (element) { case PE_PanelButtonCommand: { int delta = (option->state & State_MouseOver) ? 64 : 0; QColor slightOpaqueBlack(0, 0, 0, 63); QColor semiTransparentWhite(255, 255, 255, 127 + delta); QColor semiTransparentBlack(0, 0, 0, 127 - delta); int x, y, width, height; option->rect.getRect(&x, &y, &width, &height); QPainterPath roundRect = roundRectPath(option->rect); int radius = qMin(width, height) / 2; QBrush brush; bool darker; const QStyleOptionButton *buttonOption = qstyleoption_cast<const QStyleOptionButton *>(option); if (buttonOption && (buttonOption->features & QStyleOptionButton::Flat)) { brush = option->palette.background(); darker = (option->state & (State_Sunken | State_On)); } else { if (option->state & (State_Sunken | State_On)) { brush = option->palette.mid(); darker = !(option->state & State_Sunken); } else { brush = option->palette.button(); darker = false; } } painter->save(); painter->setRenderHint(QPainter::Antialiasing, true); painter->fillPath(roundRect, brush); if (darker) { QColor slightlyOpaqueBlack(0, 0, 0, 63); painter->fillPath(roundRect, slightlyOpaqueBlack); } int penWidth; if (radius < 10) { penWidth = 3; } else if (radius < 20) { penWidth = 5; } else { penWidth = 7; } QPen topPen(semiTransparentWhite, penWidth); QPen bottomPen(semiTransparentBlack, penWidth); if (option->state & (State_Sunken | State_On)) { qSwap(topPen, bottomPen); } int x1 = x; int x2 = x + radius; int x3 = x + width - radius; int x4 = x + width; if (option->direction == Qt::RightToLeft) { qSwap(x1, x4); qSwap(x2, x3); } QPolygon topHalf; topHalf << QPoint(x1, y) << QPoint(x4, y) << QPoint(x3, y + radius) << QPoint(x2, y + height - radius) << QPoint(x4, y + height); painter->setClipPath(roundRect); painter->setClipRegion(topHalf, Qt::IntersectClip); painter->setPen(topPen); painter->drawPath(roundRect); QPolygon bottomHalf = topHalf; bottomHalf[0] = QPoint(x4, y + height); painter->setClipPath(roundRect); painter->setClipRegion(bottomHalf, Qt::IntersectClip); painter->setPen(bottomPen); painter->drawPath(roundRect); painter->setPen(option->palette.foreground().color()); painter->setClipping(false); painter->drawPath(roundRect); painter->restore(); } break; default: QMotifStyle::drawPrimitive(element, option, painter, widget); } }
void CustomStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const { QColor backgroundColor; QPen oldPen(2); QPainterPath path; int x1, x2, y1, y2; switch (element) { case CE_PushButtonBevel: if (const QStyleOptionButton *button = qstyleoption_cast<const QStyleOptionButton *>(option)) { bool hover = (button->state & State_HasFocus); // if (hover) // drawHoverRect(painter, widget->rect()); QColor slightlyOpaqueBlack(0, 0, 0, 63); int x, y, width, height; option->rect.getRect(&x, &y, &width, &height); QPainterPath roundRect = roundRectPath(option->rect); // int radius = qMin(width, height) / 2; QBrush brush; bool darker; const QStyleOptionButton *buttonOption = qstyleoption_cast<const QStyleOptionButton *>(option); if (buttonOption && (buttonOption->features & QStyleOptionButton::Flat)) { brush = option->palette.mid(); darker = (option->state & (State_Sunken | State_On)); } else { if (option->state & (State_Sunken | State_On)) { brush = option->palette.mid(); darker = !(option->state & State_Sunken); } else { brush = option->palette.button(); darker = false; } } painter->save(); painter->setRenderHint(QPainter::Antialiasing, true); painter->fillPath(roundRect, brush); // Draw Image ... if (darker) painter->fillPath(roundRect, slightlyOpaqueBlack); QBrush normalBrush(QBrush(QColor(145, 116, 255))); painter->fillPath(roundRect, normalBrush); if (!hover) { QBrush highlightBrush(QBrush(QColor(142, 163, 133))); painter->fillPath(roundRect, highlightBrush); /* x1 =x;x2 =x+width;y1=y;y2=y+height; QLineF line1(x1+2, y1, x2-2, y1); QLineF line2(x2-2,y1,x2,y2+2); QLineF line3(x2,y2+2,x2,y2-2); QLineF line4(x2,y2-2,x2-2,y2); QLineF line5(x2-2,y2,x1,y2-2); QLineF line6(x1,y2-2,x1,y2-2); QLineF line7(x1,y2-2,x1,y1+2); QLineF line8(x1,y1+2,x1+2,y1); QPen linePen(QPen(QColor(92,135,75))); painter->drawLine(line1); painter->drawLine(line8); painter->drawLine(line7); linePen.setColor(QColor(34,63,22)); painter->drawLine(line8); painter->drawLine(line8); painter->drawLine(line8); painter->drawLine(line8); painter->drawLine(line8);*/ } /* else { QPen myPen(QPen(QColor(145, 116, 255))); painter->setPen(myPen); painter->drawRect(option->rect); QBrush normalBrush1(QBrush(QColor(145, 116, 255))); painter->fillRect(option->rect, normalBrush1); }*/ /* int penWidth; if (radius < 10) penWidth = 1; else if (radius < 20) penWidth = 1; else penWidth = 1; int delta = (option->state & State_MouseOver) ? 64 : 0; QColor semiTransparentWhite(255, 255, 255, 127 + delta); QColor semiTransparentBlack(0, 0, 0, 127 - delta); QColor semiFocusTop(255, 0, 0, 127 + delta); QColor semiFocusDown(200, 0, 100, 127 - delta); QPen topPen((hover ? semiFocusTop:semiTransparentWhite), penWidth); QPen bottomPen((hover ? semiFocusDown:semiTransparentBlack), penWidth); if (option->state & (State_Sunken | State_On)) qSwap(topPen, bottomPen); int x1 = x; int x2 = x + radius; int x3 = x + width - radius; int x4 = x + width; if (option->direction == Qt::RightToLeft) { qSwap(x1, x4); qSwap(x2, x3); } QPolygon topHalf; topHalf << QPoint(x1, y) << QPoint(x4, y) << QPoint(x3, y + radius) << QPoint(x2, y + height - radius) << QPoint(x1, y + height); painter->setClipPath(roundRect); painter->setClipRegion(topHalf, Qt::IntersectClip); painter->setPen(topPen); painter->drawPath(roundRect); // Border draw ... QPolygon bottomHalf = topHalf; bottomHalf[0] = QPoint(x4, y + height); painter->setClipPath(roundRect); painter->setClipRegion(bottomHalf, Qt::IntersectClip); painter->setPen(bottomPen); painter->drawPath(roundRect); painter->setPen(option->palette.foreground().color()); painter->setClipping(false); painter->drawPath(roundRect); */ painter->restore(); } break; case CE_PushButtonLabel: { QStyleOptionButton myButtonOption; const QStyleOptionButton *buttonOption = qstyleoption_cast<const QStyleOptionButton *>(option); if (buttonOption) { myButtonOption = *buttonOption; if (myButtonOption.palette.currentColorGroup() != QPalette::Disabled) { if (myButtonOption.state & (State_Sunken | State_On)) { myButtonOption.palette.setBrush(QPalette::ButtonText, myButtonOption.palette.brightText()); } } } QWindowsStyle::drawControl(element, &myButtonOption, painter, widget); } break; #ifndef QT_NO_PROGRESSBAR case CE_ProgressBarGroove: if (/*const QStyleOptionProgressBar *bar = */qstyleoption_cast<const QStyleOptionProgressBar *>(option)) { painter->save(); // backgroundColor = option->palette.color(widget->parentWidget()->backgroundRole()); oldPen = painter->pen(); painter->setPen(Qt::black); backgroundColor = mergedColors(QColor(0x06, 0x4C, 0xA4), QColor(0xd6, 0xd6, 0xd6)); oldPen.setColor(backgroundColor); painter->setPen(oldPen); option->rect.getCoords(&x1, &y1, &x2, &y2); path.moveTo(x1, y1); path.lineTo(x2, y1); path.lineTo(x2, y2); path.lineTo(x1, y2); path.lineTo(x1, y1); painter->drawPath(path); painter->restore(); } break; #endif default: QWindowsStyle::drawControl(element, option, painter, widget); } }