143void QCommonStyle::drawPrimitive(PrimitiveElement pe,
const QStyleOption *opt, QPainter *p,
144 const QWidget *widget)
const
146 Q_D(
const QCommonStyle);
148 case PE_FrameButtonBevel:
149 case PE_FrameButtonTool:
150 qDrawShadeRect(p, opt->rect, opt->palette,
151 opt->state & (State_Sunken | State_On), 1, 0);
153 case PE_PanelButtonCommand:
154 case PE_PanelButtonBevel:
155 case PE_PanelButtonTool:
156 case PE_IndicatorButtonDropDown:
157 qDrawShadePanel(p, opt->rect, opt->palette,
158 opt->state & (State_Sunken | State_On), 1,
159 &opt->palette.brush(QPalette::Button));
161 case PE_IndicatorItemViewItemCheck:
162 proxy()->drawPrimitive(PE_IndicatorCheckBox, opt, p, widget);
164 case PE_IndicatorCheckBox:
165 if (opt->state & State_NoChange) {
166 p->setPen(opt->palette.windowText().color());
167 p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));
168 p->drawRect(opt->rect);
169 p->drawLine(opt->rect.topLeft(), opt->rect.bottomRight());
171 qDrawShadePanel(p, opt->rect.x(), opt->rect.y(), opt->rect.width(), opt->rect.height(),
172 opt->palette, opt->state & (State_Sunken | State_On), 1,
173 &opt->palette.brush(QPalette::Button));
176 case PE_IndicatorRadioButton: {
177 QRect ir = opt->rect;
178 p->setPen(opt->palette.dark().color());
179 p->drawArc(opt->rect, 0, 5760);
180 if (opt->state & (State_Sunken | State_On)) {
181 ir.adjust(2, 2, -2, -2);
182 p->setBrush(opt->palette.windowText());
186 case PE_FrameFocusRect:
187 if (
const QStyleOptionFocusRect *fropt = qstyleoption_cast<
const QStyleOptionFocusRect *>(opt)) {
188 QColor bg = fropt->backgroundColor;
192 bg.getHsv(&h, &s, &v);
198 color = opt->palette.windowText().color();
200 const QRect focusRect = opt->rect.adjusted(1, 1, -1, -1);
201 qDrawPlainRect(p, focusRect, color, 1);
204 case PE_IndicatorMenuCheckMark: {
205 const int markW = opt->rect.width() > 7 ? 7 : opt->rect.width();
206 const int markH = markW;
207 int posX = opt->rect.x() + (opt->rect.width() - markW)/2 + 1;
208 int posY = opt->rect.y() + (opt->rect.height() - markH)/2;
216 for (i = 0; i < markW/2; ++i) {
217 a << QLineF(xx, yy, xx, yy + 2);
222 for (; i < markH; ++i) {
223 a << QLineF(xx, yy, xx, yy + 2);
227 if (!(opt->state & State_Enabled) && !(opt->state & State_On)) {
228 QPainterStateGuard psg(p);
230 p->setPen(opt->palette.light().color());
233 p->setPen((opt->state & State_On) ? opt->palette.highlightedText().color() : opt->palette.text().color());
238 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
239 if (pe == PE_FrameMenu || (frame->state & State_Sunken) || (frame->state & State_Raised)) {
240 qDrawShadePanel(p, frame->rect, frame->palette, frame->state & State_Sunken,
243 qDrawPlainRect(p, frame->rect, frame->palette.windowText().color(), frame->lineWidth);
247#if QT_CONFIG(toolbar)
248 case PE_PanelMenuBar:
249 if (widget && qobject_cast<QToolBar *>(widget->parentWidget()))
251 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)){
252 qDrawShadePanel(p, frame->rect, frame->palette,
false, frame->lineWidth,
253 &frame->palette.brush(QPalette::Button));
256 else if (
const QStyleOptionToolBar *frame = qstyleoption_cast<
const QStyleOptionToolBar *>(opt)){
257 qDrawShadePanel(p, frame->rect, frame->palette,
false, frame->lineWidth,
258 &frame->palette.brush(QPalette::Button));
264 case PE_PanelToolBar:
267#if QT_CONFIG(progressbar)
268 case PE_IndicatorProgressChunk:
270 bool vertical =
false;
271 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt))
272 vertical = !(pb->state & QStyle::State_Horizontal);
274 p->fillRect(opt->rect.x(), opt->rect.y() + 3, opt->rect.width() -2, opt->rect.height() - 6,
275 opt->palette.brush(QPalette::Highlight));
277 p->fillRect(opt->rect.x() + 2, opt->rect.y(), opt->rect.width() -6, opt->rect.height() - 2,
278 opt->palette.brush(QPalette::Highlight));
283 case PE_IndicatorBranch: {
284 static const int decoration_size = 9;
285 int mid_h = opt->rect.x() + opt->rect.width() / 2;
286 int mid_v = opt->rect.y() + opt->rect.height() / 2;
291 if (opt->state & State_Children) {
292 int delta = decoration_size / 2;
297 p->drawLine(bef_h + 2, bef_v + 4, bef_h + 6, bef_v + 4);
298 if (!(opt->state & State_Open))
299 p->drawLine(bef_h + 4, bef_v + 2, bef_h + 4, bef_v + 6);
300 QPen oldPen = p->pen();
301 p->setPen(opt->palette.dark().color());
302 p->drawRect(bef_h, bef_v, decoration_size - 1, decoration_size - 1);
305 QBrush brush(opt->palette.dark().color(), Qt::Dense4Pattern);
306 if (opt->state & State_Item) {
307 if (opt->direction == Qt::RightToLeft)
308 p->fillRect(opt->rect.left(), mid_v, bef_h - opt->rect.left(), 1, brush);
310 p->fillRect(aft_h, mid_v, opt->rect.right() - aft_h + 1, 1, brush);
312 if (opt->state & State_Sibling)
313 p->fillRect(mid_h, aft_v, 1, opt->rect.bottom() - aft_v + 1, brush);
314 if (opt->state & (State_Open | State_Children | State_Item | State_Sibling))
315 p->fillRect(mid_h, opt->rect.y(), 1, bef_v - opt->rect.y(), brush);
317 case PE_FrameStatusBarItem:
318 qDrawShadeRect(p, opt->rect, opt->palette,
true, 1, 0,
nullptr);
320 case PE_IndicatorHeaderArrow:
321 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
322 QPainterStateGuard psg(p, QPainterStateGuard::InitialState::NoSave);
323 if (header->sortIndicator & QStyleOptionHeader::SortUp) {
325 p->setPen(QPen(opt->palette.light(), 0));
326 p->drawLine(opt->rect.x() + opt->rect.width(), opt->rect.y(),
327 opt->rect.x() + opt->rect.width() / 2, opt->rect.y() + opt->rect.height());
328 p->setPen(QPen(opt->palette.dark(), 0));
329 const QPoint points[] = {
330 QPoint(opt->rect.x() + opt->rect.width() / 2, opt->rect.y() + opt->rect.height()),
331 QPoint(opt->rect.x(), opt->rect.y()),
332 QPoint(opt->rect.x() + opt->rect.width(), opt->rect.y()),
334 p->drawPolyline(points,
sizeof points /
sizeof *points);
335 }
else if (header->sortIndicator & QStyleOptionHeader::SortDown) {
337 p->setPen(QPen(opt->palette.light(), 0));
338 const QPoint points[] = {
339 QPoint(opt->rect.x(), opt->rect.y() + opt->rect.height()),
340 QPoint(opt->rect.x() + opt->rect.width(), opt->rect.y() + opt->rect.height()),
341 QPoint(opt->rect.x() + opt->rect.width() / 2, opt->rect.y()),
343 p->drawPolyline(points,
sizeof points /
sizeof *points);
344 p->setPen(QPen(opt->palette.dark(), 0));
345 p->drawLine(opt->rect.x(), opt->rect.y() + opt->rect.height(),
346 opt->rect.x() + opt->rect.width() / 2, opt->rect.y());
351 case PE_FrameTabBarBase:
352 if (
const QStyleOptionTabBarBase *tbb
353 = qstyleoption_cast<
const QStyleOptionTabBarBase *>(opt)) {
354 QPainterStateGuard psg(p);
355 switch (tbb->shape) {
356 case QTabBar::RoundedNorth:
357 case QTabBar::TriangularNorth:
358 p->setPen(QPen(tbb->palette.light(), 0));
359 p->drawLine(tbb->rect.topLeft(), tbb->rect.topRight());
361 case QTabBar::RoundedWest:
362 case QTabBar::TriangularWest:
363 p->setPen(QPen(tbb->palette.light(), 0));
364 p->drawLine(tbb->rect.topLeft(), tbb->rect.bottomLeft());
366 case QTabBar::RoundedSouth:
367 case QTabBar::TriangularSouth:
368 p->setPen(QPen(tbb->palette.shadow(), 0));
369 p->drawLine(tbb->rect.left(), tbb->rect.bottom(),
370 tbb->rect.right(), tbb->rect.bottom());
371 p->setPen(QPen(tbb->palette.dark(), 0));
372 p->drawLine(tbb->rect.left(), tbb->rect.bottom() - 1,
373 tbb->rect.right() - 1, tbb->rect.bottom() - 1);
375 case QTabBar::RoundedEast:
376 case QTabBar::TriangularEast:
377 p->setPen(QPen(tbb->palette.dark(), 0));
378 p->drawLine(tbb->rect.topRight(), tbb->rect.bottomRight());
383 case PE_IndicatorTabClose: {
384 if (d->tabBarcloseButtonIcon.isNull())
385 d->tabBarcloseButtonIcon = proxy()->standardIcon(QStyle::SP_TabCloseButton, opt, widget);
387 const int size = proxy()->pixelMetric(QStyle::PM_SmallIconSize, opt, widget);
388 QIcon::Mode mode = opt->state & State_Enabled ?
389 (opt->state & State_Raised ? QIcon::Active : QIcon::Normal)
391 if (!opt->state.testAnyFlags(State_Raised | State_Sunken | State_Selected))
392 mode = QIcon::Disabled;
394 QIcon::State state = opt->state & State_Sunken ? QIcon::On : QIcon::Off;
395 QPixmap pixmap = d->tabBarcloseButtonIcon.pixmap(QSize(size, size), QStyleHelper::getDpr(p), mode, state);
396 proxy()->drawItemPixmap(p, opt->rect, Qt::AlignCenter, pixmap);
402 case PE_FrameTabWidget:
404 qDrawWinPanel(p, opt->rect, opt->palette,
false,
nullptr);
406 case PE_FrameLineEdit:
407 proxy()->drawPrimitive(PE_Frame, opt, p, widget);
409#if QT_CONFIG(groupbox)
410 case PE_FrameGroupBox:
411 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
412 if (frame->features & QStyleOptionFrame::Flat) {
413 QRect fr = frame->rect;
414 QPoint p1(fr.x(), fr.y() + 1);
415 QPoint p2(fr.x() + fr.width(), p1.y());
416 qDrawShadeLine(p, p1, p2, frame->palette,
true,
417 frame->lineWidth, frame->midLineWidth);
419 qDrawShadeRect(p, frame->rect.x(), frame->rect.y(), frame->rect.width(),
420 frame->rect.height(), frame->palette,
true,
421 frame->lineWidth, frame->midLineWidth);
426#if QT_CONFIG(dockwidget)
427 case PE_FrameDockWidget:
428 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
429 int lw = frame->lineWidth;
431 lw = proxy()->pixelMetric(PM_DockWidgetFrameWidth, opt, widget);
433 qDrawShadePanel(p, frame->rect, frame->palette,
false, lw);
437#if QT_CONFIG(toolbar)
438 case PE_IndicatorToolBarHandle: {
439 QPainterStateGuard psg(p);
440 p->translate(opt->rect.x(), opt->rect.y());
441 if (opt->state & State_Horizontal) {
442 int x = opt->rect.width() / 3;
443 if (opt->direction == Qt::RightToLeft)
445 if (opt->rect.height() > 4) {
446 qDrawShadePanel(p, x, 2, 3, opt->rect.height() - 4,
447 opt->palette,
false, 1,
nullptr);
448 qDrawShadePanel(p, x+3, 2, 3, opt->rect.height() - 4,
449 opt->palette,
false, 1,
nullptr);
452 if (opt->rect.width() > 4) {
453 int y = opt->rect.height() / 3;
454 qDrawShadePanel(p, 2, y, opt->rect.width() - 4, 3,
455 opt->palette,
false, 1,
nullptr);
456 qDrawShadePanel(p, 2, y+3, opt->rect.width() - 4, 3,
457 opt->palette,
false, 1,
nullptr);
462 case PE_IndicatorToolBarSeparator:
465 if (opt->state & State_Horizontal) {
466 p1 = QPoint(opt->rect.width()/2, 0);
467 p2 = QPoint(p1.x(), opt->rect.height());
469 p1 = QPoint(0, opt->rect.height()/2);
470 p2 = QPoint(opt->rect.width(), p1.y());
472 qDrawShadeLine(p, p1, p2, opt->palette, 1, 1, 0);
476#if QT_CONFIG(spinbox)
477 case PE_IndicatorSpinPlus:
478 case PE_IndicatorSpinMinus: {
480 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget);
481 QRect br = r.adjusted(fw, fw, -fw, -fw);
486 QPainterStateGuard psg(p);
487 const qreal devicePixelRatio = QStyleHelper::getDpr(p);
488 if (!qFuzzyCompare(devicePixelRatio, qreal(1))) {
489 const qreal inverseScale = qreal(1) / devicePixelRatio;
490 p->scale(inverseScale, inverseScale);
491 x = qRound(devicePixelRatio * x);
492 y = qRound(devicePixelRatio * y);
493 w = qRound(devicePixelRatio * w);
494 h = qRound(devicePixelRatio * h);
495 p->translate(0.5, 0.5);
497 int len = std::min(w, h);
500 int step = (len + 4) / 5;
503 const int step2 = step / 2;
504 QPoint center(x + w / 2, y + h / 2);
505 if (opt->state & State_Sunken) {
506 center += QPoint(proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget),
507 proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget));
509 p->translate(center);
510 p->fillRect(-len / 2, -step2, len, step, opt->palette.buttonText());
511 if (pe == PE_IndicatorSpinPlus)
512 p->fillRect(-step2, -len / 2, step, len, opt->palette.buttonText());
514 case PE_IndicatorSpinUp:
515 case PE_IndicatorSpinDown: {
517 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget);
523 QPainterStateGuard psg(p);
524 const qreal devicePixelRatio = QStyleHelper::getDpr(p);
525 if (!qFuzzyCompare(devicePixelRatio, qreal(1))) {
526 const qreal inverseScale = qreal(1) / devicePixelRatio;
527 p->scale(inverseScale, inverseScale);
528 x = qRound(devicePixelRatio * x);
529 y = qRound(devicePixelRatio * y);
530 w = qRound(devicePixelRatio * w);
531 h = qRound(devicePixelRatio * h);
532 p->translate(0.5, 0.5);
542 int sx = x + w / 2 - sw / 2;
543 int sy = y + h / 2 - sh / 2;
545 if (pe == PE_IndicatorSpinUp && fw)
550 if (opt->state & State_Sunken) {
551 bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget);
552 bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget);
554 p->translate(sx + bsx, sy + bsy);
555 p->setPen(opt->palette.buttonText().color());
556 p->setBrush(opt->palette.buttonText());
557 if (pe == PE_IndicatorSpinDown) {
558 const QPoint points[] = { QPoint(0, 1), QPoint(sw-1, 1), QPoint(sh-2, sh-1) };
559 p->drawPolygon(points,
sizeof points /
sizeof *points);
561 const QPoint points[] = { QPoint(0, sh-1), QPoint(sw-1, sh-1), QPoint(sh-2, 1) };
562 p->drawPolygon(points,
sizeof points /
sizeof *points);
566 case PE_PanelTipLabel: {
567 const QBrush brush(opt->palette.toolTipBase());
568 qDrawPlainRect(p, opt->rect, opt->palette.toolTipText().color(), 1, &brush);
572 case PE_IndicatorTabTear:
573 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
574 bool rtl = tab->direction == Qt::RightToLeft;
575 const bool horizontal = tab->rect.height() > tab->rect.width();
576 const bool isSelected = tab->state.testFlag(State_Selected);
577 const int margin = 4;
581 QRect rect = tab->rect.adjusted(rtl ? margin : 0, 0, rtl ? 1 : -margin, 0);
582 rect.setTop(rect.top() + (isSelected ? 1 : 3));
583 rect.setBottom(rect.bottom() - (isSelected ? 0 : 2));
585 path.moveTo(QPoint(rtl ? rect.right() : rect.left(), rect.top()));
587 for (
int jags = 1; jags <= count; ++jags, rtl = !rtl)
588 path.lineTo(QPoint(rtl ? rect.left() : rect.right(), rect.top() + jags * rect.height()/count));
590 QRect rect = tab->rect.adjusted(0, 0, 0, -margin);
591 rect.setLeft(rect.left() + (isSelected ? 1 : 3));
592 rect.setRight(rect.right() - (isSelected ? 0 : 2));
594 path.moveTo(QPoint(rect.left(), rect.top()));
596 for (
int jags = 1; jags <= count; ++jags, rtl = !rtl)
597 path.lineTo(QPoint(rect.left() + jags * rect.width()/count, rtl ? rect.top() : rect.bottom()));
600 p->setPen(QPen(tab->palette.dark(), qreal(.8)));
601 p->setBrush(tab->palette.window());
602 p->setRenderHint(QPainter::Antialiasing);
607#if QT_CONFIG(lineedit)
608 case PE_PanelLineEdit:
609 if (
const QStyleOptionFrame *panel = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
610 p->fillRect(panel->rect.adjusted(panel->lineWidth, panel->lineWidth, -panel->lineWidth, -panel->lineWidth),
611 panel->palette.brush(QPalette::Base));
613 if (panel->lineWidth > 0)
614 proxy()->drawPrimitive(PE_FrameLineEdit, panel, p, widget);
618#if QT_CONFIG(columnview)
619 case PE_IndicatorColumnViewArrow: {
620 if (
const QStyleOptionViewItem *viewOpt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
621 bool reverse = (viewOpt->direction == Qt::RightToLeft);
622 QPainterStateGuard psg(p);
624 int x = viewOpt->rect.x() + 1;
625 int offset = (viewOpt->rect.height() / 3);
626 int height = (viewOpt->rect.height()) - offset * 2;
629 int x2 = x + height - 1;
631 x = viewOpt->rect.x() + viewOpt->rect.width() - 1;
634 path.moveTo(x, viewOpt->rect.y() + offset);
635 path.lineTo(x, viewOpt->rect.y() + offset + height);
636 path.lineTo(x2, viewOpt->rect.y() + offset+height/2);
638 if (viewOpt->state & QStyle::State_Selected ) {
639 if (viewOpt->showDecorationSelected) {
640 QColor color = viewOpt->palette.color(QPalette::Active, QPalette::HighlightedText);
644 QColor color = viewOpt->palette.color(QPalette::Active, QPalette::WindowText);
650 QColor color = viewOpt->palette.color(QPalette::Active, QPalette::Mid);
657 if (!(viewOpt->state & QStyle::State_Selected)) {
659 lines.moveTo(x, viewOpt->rect.y() + offset);
660 lines.lineTo(x, viewOpt->rect.y() + offset + height);
661 lines.moveTo(x, viewOpt->rect.y() + offset);
662 lines.lineTo(x2, viewOpt->rect.y() + offset+height/2);
663 QColor color = viewOpt->palette.color(QPalette::Active, QPalette::Dark);
670 case PE_IndicatorItemViewItemDrop: {
671 QRect rect = opt->rect;
672 if (opt->rect.height() == 0)
673 p->drawLine(rect.topLeft(), rect.topRight());
677#if QT_CONFIG(itemviews)
678 case PE_PanelItemViewRow:
679 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
680 QPalette::ColorGroup cg = (widget ? widget->isEnabled() : (vopt->state & QStyle::State_Enabled))
681 ? QPalette::Normal : QPalette::Disabled;
682 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))
683 cg = QPalette::Inactive;
685 if ((vopt->state & QStyle::State_Selected) && vopt->showDecorationSelected)
686 p->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::Highlight));
687 else if (vopt->features & QStyleOptionViewItem::Alternate)
688 p->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::AlternateBase));
691 case PE_PanelItemViewItem:
692 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
693 QPalette::ColorGroup cg = (widget ? widget->isEnabled() : (vopt->state & QStyle::State_Enabled))
694 ? QPalette::Normal : QPalette::Disabled;
695 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))
696 cg = QPalette::Inactive;
698 if (vopt->showDecorationSelected && (vopt->state & QStyle::State_Selected)) {
699 p->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::Highlight));
701 if (vopt->backgroundBrush.style() != Qt::NoBrush) {
702 QPainterStateGuard psg(p);
703 p->setBrushOrigin(vopt->rect.topLeft());
704 p->fillRect(vopt->rect, vopt->backgroundBrush);
707 if (vopt->state & QStyle::State_Selected) {
708 QRect textRect = subElementRect(QStyle::SE_ItemViewItemText, opt, widget);
709 p->fillRect(textRect, vopt->palette.brush(cg, QPalette::Highlight));
715 case PE_PanelScrollAreaCorner: {
716 const QBrush brush(opt->palette.brush(QPalette::Window));
717 p->fillRect(opt->rect, brush);
719 case PE_IndicatorArrowUp:
720 case PE_IndicatorArrowDown:
721 case PE_IndicatorArrowRight:
722 case PE_IndicatorArrowLeft:
724 const QRect &r = opt->rect;
725 if (r.width() <= 1 || r.height() <= 1)
727 int size = qMin(r.height(), r.width());
729 const qreal dpr = QStyleHelper::getDpr(p);
730 const QString pixmapName = QStyleHelper::uniqueName(
"$qt_ia-"_L1
731 % QLatin1StringView(metaObject()->className())
732 % HexString<uint>(pe),
733 opt, QSize(size, size), dpr);
734 if (!QPixmapCache::find(pixmapName, &pixmap)) {
736 const int border = 1 * dpr;
737 const int sizeDpr = size * dpr;
738 int width = sizeDpr - 2 * border - 1;
739 int height = width / 2;
740 const int add = ((width & 1) == 1);
741 if (pe == PE_IndicatorArrowRight || pe == PE_IndicatorArrowLeft)
742 std::swap(width, height);
743 pixmap = styleCachePixmap(QSize(sizeDpr, sizeDpr), 1);
745 std::array<QPointF, 4> poly;
747 case PE_IndicatorArrowUp:
748 poly = {QPointF(0, height), QPointF(width, height),
749 QPointF(width / 2 + add, 0), QPointF(width / 2, 0)};
751 case PE_IndicatorArrowDown:
752 poly = {QPointF(0, 0), QPointF(width, 0),
753 QPointF(width / 2 + add, height), QPointF(width / 2, height)};
755 case PE_IndicatorArrowRight:
756 poly = {QPointF(0, 0), QPointF(0, height),
757 QPointF(width, height / 2 + add), QPointF(width, height / 2)};
759 case PE_IndicatorArrowLeft:
760 poly = {QPointF(width, 0), QPointF(width, height),
761 QPointF(0, height / 2 + add), QPointF(0, height / 2)};
767 QPainter imagePainter(&pixmap);
768 imagePainter.translate((sizeDpr - width) / 2, (sizeDpr - height) / 2);
769 if (opt->state & State_Sunken) {
770 const auto bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget);
771 const auto bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget);
772 imagePainter.translate(bsx, bsy);
774 imagePainter.setPen(opt->palette.buttonText().color());
775 imagePainter.setBrush(opt->palette.buttonText());
777 if (!(opt->state & State_Enabled)) {
778 const int ofs = qRound(1 * dpr);
779 imagePainter.translate(ofs, ofs);
780 imagePainter.setBrush(opt->palette.light());
781 imagePainter.setPen(opt->palette.light().color());
782 imagePainter.drawPolygon(poly.data(),
int(poly.size()));
783 imagePainter.drawPoints(poly.data(),
int(poly.size()));
784 imagePainter.translate(-ofs, -ofs);
785 imagePainter.setBrush(opt->palette.mid());
786 imagePainter.setPen(opt->palette.mid().color());
788 imagePainter.drawPolygon(poly.data(),
int(poly.size()));
790 imagePainter.drawPoints(poly.data(),
int(poly.size()));
792 pixmap.setDevicePixelRatio(dpr);
793 QPixmapCache::insert(pixmapName, pixmap);
795 int xOffset = r.x() + (r.width() - size)/2;
796 int yOffset = r.y() + (r.height() - size)/2;
797 p->drawPixmap(xOffset, yOffset, pixmap);
1297void QCommonStyle::drawControl(ControlElement element,
const QStyleOption *opt,
1298 QPainter *p,
const QWidget *widget)
const
1300 Q_D(
const QCommonStyle);
1304 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
1305 proxy()->drawControl(CE_PushButtonBevel, btn, p, widget);
1306 QStyleOptionButton subopt = *btn;
1307 subopt.rect = subElementRect(SE_PushButtonContents, btn, widget);
1308 proxy()->drawControl(CE_PushButtonLabel, &subopt, p, widget);
1309 if (btn->state & State_HasFocus) {
1310 QStyleOptionFocusRect fropt;
1311 fropt.QStyleOption::operator=(*btn);
1312 fropt.rect = subElementRect(SE_PushButtonFocusRect, btn, widget);
1313 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
1317 case CE_PushButtonBevel:
1318 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
1319 QRect br = btn->rect;
1320 int dbi = proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
1321 if (btn->features & QStyleOptionButton::DefaultButton)
1322 proxy()->drawPrimitive(PE_FrameDefaultButton, opt, p, widget);
1323 if (btn->features & QStyleOptionButton::AutoDefaultButton)
1324 br.setCoords(br.left() + dbi, br.top() + dbi, br.right() - dbi, br.bottom() - dbi);
1325 if (!(btn->features & (QStyleOptionButton::Flat | QStyleOptionButton::CommandLinkButton))
1326 || btn->state & (State_Sunken | State_On)
1327 || (btn->features & QStyleOptionButton::CommandLinkButton && btn->state & State_MouseOver)) {
1328 QStyleOptionButton tmpBtn = *btn;
1330 proxy()->drawPrimitive(PE_PanelButtonCommand, &tmpBtn, p, widget);
1332 if (btn->features & QStyleOptionButton::HasMenu) {
1333 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, btn, widget);
1334 QRect ir = btn->rect;
1335 QStyleOptionButton newBtn = *btn;
1336 newBtn.rect = QRect(ir.right() - mbi - 2, ir.height()/2 - mbi/2 + 3, mbi - 6, mbi - 6);
1337 newBtn.rect = visualRect(btn->direction, br, newBtn.rect);
1338 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, p, widget);
1342 case CE_PushButtonLabel:
1343 if (
const QStyleOptionButton *button = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
1344 QRect textRect = button->rect;
1345 int tf = Qt::AlignVCenter | Qt::TextShowMnemonic;
1346 if (!proxy()->styleHint(SH_UnderlineShortcut, button, widget))
1347 tf |= Qt::TextHideMnemonic;
1349 if (button->features & QStyleOptionButton::HasMenu) {
1350 int indicatorSize = proxy()->pixelMetric(PM_MenuButtonIndicator, button, widget);
1351 if (button->direction == Qt::LeftToRight)
1352 textRect = textRect.adjusted(0, 0, -indicatorSize, 0);
1354 textRect = textRect.adjusted(indicatorSize, 0, 0, 0);
1357 if (!button->icon.isNull()) {
1359 QIcon::Mode mode = button->state & State_Enabled ? QIcon::Normal : QIcon::Disabled;
1360 if (mode == QIcon::Normal && button->state & State_HasFocus)
1361 mode = QIcon::Active;
1362 QIcon::State state = QIcon::Off;
1363 if (button->state & State_On)
1366 QPixmap pixmap = button->icon.pixmap(button->iconSize, QStyleHelper::getDpr(p), mode, state);
1367 int pixmapWidth = pixmap.width() / pixmap.devicePixelRatio();
1368 int pixmapHeight = pixmap.height() / pixmap.devicePixelRatio();
1369 int labelWidth = pixmapWidth;
1370 int labelHeight = pixmapHeight;
1371 int iconSpacing = 4;
1372 if (!button->text.isEmpty()) {
1373 int textWidth = button->fontMetrics.boundingRect(opt->rect, tf, button->text).width();
1374 labelWidth += (textWidth + iconSpacing);
1377 QRect iconRect = QRect(textRect.x() + (textRect.width() - labelWidth) / 2,
1378 textRect.y() + (textRect.height() - labelHeight) / 2,
1379 pixmapWidth, pixmapHeight);
1381 iconRect = visualRect(button->direction, textRect, iconRect);
1383 if (button->direction == Qt::RightToLeft)
1384 textRect.setRight(iconRect.left() - iconSpacing / 2);
1386 textRect.setLeft(iconRect.left() + iconRect.width() + iconSpacing / 2);
1389 if (p->layoutDirection() == button->direction)
1390 tf |= Qt::AlignLeft;
1392 tf |= Qt::AlignRight;
1394 if (button->state & (State_On | State_Sunken))
1395 iconRect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget),
1396 proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget));
1397 p->drawPixmap(iconRect, pixmap);
1399 tf |= Qt::AlignHCenter;
1401 if (button->state & (State_On | State_Sunken))
1402 textRect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget),
1403 proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget));
1405 proxy()->drawItemText(p, textRect, tf, button->palette, (button->state & State_Enabled),
1406 button->text, QPalette::ButtonText);
1409 case CE_RadioButton:
1411 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
1412 bool isRadio = (element == CE_RadioButton);
1413 QStyleOptionButton subopt = *btn;
1414 subopt.rect = subElementRect(isRadio ? SE_RadioButtonIndicator
1415 : SE_CheckBoxIndicator, btn, widget);
1416 proxy()->drawPrimitive(isRadio ? PE_IndicatorRadioButton : PE_IndicatorCheckBox,
1417 &subopt, p, widget);
1418 subopt.rect = subElementRect(isRadio ? SE_RadioButtonContents
1419 : SE_CheckBoxContents, btn, widget);
1420 proxy()->drawControl(isRadio ? CE_RadioButtonLabel : CE_CheckBoxLabel, &subopt, p, widget);
1421 if (btn->state & State_HasFocus) {
1422 QStyleOptionFocusRect fropt;
1423 fropt.QStyleOption::operator=(*btn);
1424 fropt.rect = subElementRect(isRadio ? SE_RadioButtonFocusRect
1425 : SE_CheckBoxFocusRect, btn, widget);
1426 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
1430 case CE_RadioButtonLabel:
1431 case CE_CheckBoxLabel:
1432 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
1433 int alignment = visualAlignment(btn->direction, Qt::AlignLeft | Qt::AlignVCenter);
1435 if (!proxy()->styleHint(SH_UnderlineShortcut, btn, widget))
1436 alignment |= Qt::TextHideMnemonic;
1437 QRect textRect = btn->rect;
1438 if (!btn->icon.isNull()) {
1439 const auto pix = btn->icon.pixmap(btn->iconSize, QStyleHelper::getDpr(p),
1440 btn->state & State_Enabled ? QIcon::Normal : QIcon::Disabled);
1441 proxy()->drawItemPixmap(p, btn->rect, alignment, pix);
1442 if (btn->direction == Qt::RightToLeft)
1443 textRect.setRight(textRect.right() - btn->iconSize.width() - 4);
1445 textRect.setLeft(textRect.left() + btn->iconSize.width() + 4);
1447 if (!btn->text.isEmpty()){
1448 proxy()->drawItemText(p, textRect, alignment | Qt::TextShowMnemonic,
1449 btn->palette, btn->state & State_Enabled, btn->text, QPalette::WindowText);
1454 case CE_MenuScroller: {
1455 QStyleOption arrowOpt = *opt;
1456 arrowOpt.state |= State_Enabled;
1457 proxy()->drawPrimitive(((opt->state & State_DownArrow) ? PE_IndicatorArrowDown : PE_IndicatorArrowUp),
1458 &arrowOpt, p, widget);
1460 case CE_MenuTearoff:
1461 if (opt->state & State_Selected)
1462 p->fillRect(opt->rect, opt->palette.brush(QPalette::Highlight));
1464 p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));
1465 p->setPen(QPen(opt->palette.dark().color(), 1, Qt::DashLine));
1466 p->drawLine(opt->rect.x() + 2, opt->rect.y() + opt->rect.height() / 2 - 1,
1467 opt->rect.x() + opt->rect.width() - 4,
1468 opt->rect.y() + opt->rect.height() / 2 - 1);
1469 p->setPen(QPen(opt->palette.light().color(), 1, Qt::DashLine));
1470 p->drawLine(opt->rect.x() + 2, opt->rect.y() + opt->rect.height() / 2,
1471 opt->rect.x() + opt->rect.width() - 4, opt->rect.y() + opt->rect.height() / 2);
1474#if QT_CONFIG(menubar)
1475 case CE_MenuBarItem:
1476 if (
const QStyleOptionMenuItem *mbi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
1477 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip
1478 | Qt::TextSingleLine;
1479 if (!proxy()->styleHint(SH_UnderlineShortcut, mbi, widget))
1480 alignment |= Qt::TextHideMnemonic;
1481 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
1482 QPixmap pix = mbi->icon.pixmap(QSize(iconExtent, iconExtent), QStyleHelper::getDpr(p), (mbi->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled);
1484 proxy()->drawItemPixmap(p,mbi->rect, alignment, pix);
1486 proxy()->drawItemText(p, mbi->rect, alignment, mbi->palette, mbi->state & State_Enabled,
1487 mbi->text, QPalette::ButtonText);
1490 case CE_MenuBarEmptyArea:
1491 if (widget && !widget->testAttribute(Qt::WA_NoSystemBackground))
1492 p->eraseRect(opt->rect);
1495#if QT_CONFIG(progressbar)
1496 case CE_ProgressBar:
1497 if (
const QStyleOptionProgressBar *pb
1498 = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
1499 QStyleOptionProgressBar subopt = *pb;
1500 subopt.rect = subElementRect(SE_ProgressBarGroove, pb, widget);
1501 proxy()->drawControl(CE_ProgressBarGroove, &subopt, p, widget);
1502 subopt.rect = subElementRect(SE_ProgressBarContents, pb, widget);
1503 proxy()->drawControl(CE_ProgressBarContents, &subopt, p, widget);
1504 if (pb->textVisible) {
1505 subopt.rect = subElementRect(SE_ProgressBarLabel, pb, widget);
1506 proxy()->drawControl(CE_ProgressBarLabel, &subopt, p, widget);
1510 case CE_ProgressBarGroove:
1511 if (opt->rect.isValid())
1512 qDrawShadePanel(p, opt->rect, opt->palette,
true, 1,
1513 &opt->palette.brush(QPalette::Window));
1515 case CE_ProgressBarLabel:
1516 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
1517 const bool vertical = !(pb->state & QStyle::State_Horizontal);
1519 QPalette::ColorRole textRole = QPalette::NoRole;
1520 if ((pb->textAlignment & Qt::AlignCenter) && pb->textVisible
1521 && ((qint64(pb->progress) - qint64(pb->minimum)) * 2 >= (qint64(pb->maximum) - qint64(pb->minimum)))) {
1522 textRole = QPalette::HighlightedText;
1524 QRect shadowRect(pb->rect);
1525 shadowRect.translate(1,1);
1526 QColor shadowColor = (pb->palette.color(textRole).value() <= 128)
1527 ? QColor(255,255,255,160) : QColor(0,0,0,160);
1528 QPalette shadowPalette = pb->palette;
1529 shadowPalette.setColor(textRole, shadowColor);
1530 proxy()->drawItemText(p, shadowRect, Qt::AlignCenter | Qt::TextSingleLine, shadowPalette,
1531 pb->state & State_Enabled, pb->text, textRole);
1533 proxy()->drawItemText(p, pb->rect, Qt::AlignCenter | Qt::TextSingleLine, pb->palette,
1534 pb->state & State_Enabled, pb->text, textRole);
1538 case CE_ProgressBarContents:
1539 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
1541 QRect rect = pb->rect;
1542 const bool vertical = !(pb->state & QStyle::State_Horizontal);
1543 const bool inverted = pb->invertedAppearance;
1544 qint64 minimum = qint64(pb->minimum);
1545 qint64 maximum = qint64(pb->maximum);
1546 qint64 progress = qint64(pb->progress);
1551 rect = QRect(rect.y(), rect.x(), rect.height(), rect.width());
1553 m.translate(0, -(rect.height() + rect.y()*2));
1556 QPalette pal2 = pb->palette;
1558 if (pal2.highlight() == pal2.window())
1559 pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active,
1560 QPalette::Highlight));
1561 bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical);
1564 int w = rect.width();
1565 if (pb->minimum == 0 && pb->maximum == 0) {
1567 int x = (progress - minimum) % (w * 2);
1570 x = reverse ? rect.right() - x : x + rect.x();
1571 p->setPen(QPen(pal2.highlight().color(), 4));
1572 p->drawLine(x, rect.y(), x, rect.height());
1574 const int unit_width = proxy()->pixelMetric(PM_ProgressBarChunkWidth, pb, widget);
1580 u = ((rect.width() + unit_width) / unit_width);
1583 qint64 p_v = progress - minimum;
1584 qint64 t_s = (maximum - minimum) ? (maximum - minimum) : qint64(1);
1586 if (u > 0 && p_v >= INT_MAX / u && t_s >= u) {
1594 tnu = nu = p_v * u / t_s;
1596 if (nu * unit_width > w)
1604 int x0 = reverse ? rect.right() - ((unit_width > 1) ? unit_width : 0)
1607 QStyleOptionProgressBar pbBits = *pb;
1609 pbBits.palette = pal2;
1610 int myY = pbBits.rect.y();
1611 int myHeight = pbBits.rect.height();
1612 pbBits.state &= QStyle::State_Horizontal;
1613 for (
int i = 0; i < nu; ++i) {
1614 pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);
1615 pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();
1616 proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
1617 x += reverse ? -unit_width : unit_width;
1623 int pixels_left = w - (nu * unit_width);
1624 int offset = reverse ? x0 + x + unit_width-pixels_left : x0 + x;
1625 pbBits.rect.setRect(offset, myY, pixels_left, myHeight);
1626 pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();
1627 proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
1633 case CE_HeaderLabel:
1634 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
1635 QRect rect = header->rect;
1636 if (!header->icon.isNull()) {
1637 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
1639 = header->icon.pixmap(QSize(iconExtent, iconExtent), QStyleHelper::getDpr(p), (header->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled);
1640 int pixw = pixmap.width() / pixmap.devicePixelRatio();
1642 QRect aligned = alignedRect(header->direction, header->iconAlignment, pixmap.size() / pixmap.devicePixelRatio(), rect);
1643 QRect inter = aligned.intersected(rect);
1644 p->drawPixmap(inter.x(), inter.y(), pixmap,
1645 inter.x() - aligned.x(), inter.y() - aligned.y(),
1646 aligned.width() * pixmap.devicePixelRatio(),
1647 pixmap.height() * pixmap.devicePixelRatio());
1649 const int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget);
1650 if (header->direction == Qt::LeftToRight)
1651 rect.setLeft(rect.left() + pixw + margin);
1653 rect.setRight(rect.right() - pixw - margin);
1655 QFontMetrics fm(header->fontMetrics);
1656 if (header->state & QStyle::State_On) {
1657 QFont fnt = p->font();
1659 if (!(fnt.resolveMask() & QFont::WeightResolved)) {
1662 fm = QFontMetrics((p->font()));
1665 QString text = header->text;
1666 if (
const QStyleOptionHeaderV2 *headerV2 = qstyleoption_cast<
const QStyleOptionHeaderV2 *>(header)) {
1667 if (headerV2->textElideMode != Qt::ElideNone)
1668 text = fm.elidedText(header->text, headerV2->textElideMode, rect.width());
1670 proxy()->drawItemText(p, rect, header->textAlignment, header->palette,
1671 header->state.testFlag(State_Enabled), text, QPalette::ButtonText);
1674#if QT_CONFIG(toolbutton)
1675 case CE_ToolButtonLabel:
1676 if (
const QStyleOptionToolButton *toolbutton
1677 = qstyleoption_cast<
const QStyleOptionToolButton *>(opt)) {
1678 QRect rect = toolbutton->rect;
1681 if (toolbutton->state & (State_Sunken | State_On)) {
1682 shiftX = proxy()->pixelMetric(PM_ButtonShiftHorizontal, toolbutton, widget);
1683 shiftY = proxy()->pixelMetric(PM_ButtonShiftVertical, toolbutton, widget);
1686 bool hasArrow = toolbutton->features & QStyleOptionToolButton::Arrow;
1687 if (((!hasArrow && toolbutton->icon.isNull()) && !toolbutton->text.isEmpty())
1688 || toolbutton->toolButtonStyle == Qt::ToolButtonTextOnly) {
1689 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;
1690 if (!proxy()->styleHint(SH_UnderlineShortcut, opt, widget))
1691 alignment |= Qt::TextHideMnemonic;
1692 rect.translate(shiftX, shiftY);
1693 p->setFont(toolbutton->font);
1694 const QString text = d->toolButtonElideText(toolbutton, rect, alignment);
1695 proxy()->drawItemText(p, rect, alignment, toolbutton->palette,
1696 opt->state & State_Enabled, text,
1697 QPalette::ButtonText);
1700 QSize pmSize = toolbutton->iconSize;
1701 if (!toolbutton->icon.isNull()) {
1702 QIcon::State state = toolbutton->state & State_On ? QIcon::On : QIcon::Off;
1704 if (!(toolbutton->state & State_Enabled))
1705 mode = QIcon::Disabled;
1706 else if ((opt->state & State_MouseOver) && (opt->state & State_AutoRaise))
1707 mode = QIcon::Active;
1709 mode = QIcon::Normal;
1710 pm = toolbutton->icon.pixmap(toolbutton->rect.size().boundedTo(toolbutton->iconSize), QStyleHelper::getDpr(p),
1712 pmSize = pm.size() / pm.devicePixelRatio();
1715 if (toolbutton->toolButtonStyle != Qt::ToolButtonIconOnly) {
1716 p->setFont(toolbutton->font);
1719 int alignment = Qt::TextShowMnemonic;
1720 if (!proxy()->styleHint(SH_UnderlineShortcut, opt, widget))
1721 alignment |= Qt::TextHideMnemonic;
1723 if (toolbutton->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
1724 pr.setHeight(pmSize.height() + 4);
1725 tr.adjust(0, pr.height() - 1, 0, -1);
1726 pr.translate(shiftX, shiftY);
1728 proxy()->drawItemPixmap(p, pr, Qt::AlignCenter, pm);
1730 drawArrow(proxy(), toolbutton, pr, p, widget);
1732 alignment |= Qt::AlignCenter;
1734 pr.setWidth(pmSize.width() + 4);
1735 tr.adjust(pr.width(), 0, 0, 0);
1736 pr.translate(shiftX, shiftY);
1738 proxy()->drawItemPixmap(p, QStyle::visualRect(opt->direction, rect, pr), Qt::AlignCenter, pm);
1740 drawArrow(proxy(), toolbutton, pr, p, widget);
1742 alignment |= Qt::AlignLeft | Qt::AlignVCenter;
1744 tr.translate(shiftX, shiftY);
1745 const QString text = d->toolButtonElideText(toolbutton, tr, alignment);
1746 proxy()->drawItemText(p, QStyle::visualRect(opt->direction, rect, tr), alignment, toolbutton->palette,
1747 toolbutton->state & State_Enabled, text,
1748 QPalette::ButtonText);
1750 rect.translate(shiftX, shiftY);
1752 drawArrow(proxy(), toolbutton, rect, p, widget);
1754 proxy()->drawItemPixmap(p, rect, Qt::AlignCenter, pm);
1761#if QT_CONFIG(toolbox)
1763 if (
const QStyleOptionToolBox *tb = qstyleoption_cast<
const QStyleOptionToolBox *>(opt)) {
1764 proxy()->drawControl(CE_ToolBoxTabShape, tb, p, widget);
1765 proxy()->drawControl(CE_ToolBoxTabLabel, tb, p, widget);
1768 case CE_ToolBoxTabShape:
1769 if (
const QStyleOptionToolBox *tb = qstyleoption_cast<
const QStyleOptionToolBox *>(opt)) {
1770 p->setPen(tb->palette.mid().color().darker(150));
1771 int d = 20 + tb->rect.height() - 3;
1772 if (tb->direction != Qt::RightToLeft) {
1773 const QPoint points[] = {
1774 QPoint(-1, tb->rect.height() + 1),
1776 QPoint(tb->rect.width() - d, 1),
1777 QPoint(tb->rect.width() - 20, tb->rect.height() - 2),
1778 QPoint(tb->rect.width() - 1, tb->rect.height() - 2),
1779 QPoint(tb->rect.width() - 1, tb->rect.height() + 1),
1780 QPoint(-1, tb->rect.height() + 1),
1782 p->drawPolygon(points,
sizeof points /
sizeof *points);
1784 const QPoint points[] = {
1785 QPoint(tb->rect.width(), tb->rect.height() + 1),
1786 QPoint(tb->rect.width(), 1),
1788 QPoint(20 - 1, tb->rect.height() - 2),
1789 QPoint(0, tb->rect.height() - 2),
1790 QPoint(0, tb->rect.height() + 1),
1791 QPoint(tb->rect.width(), tb->rect.height() + 1),
1793 p->drawPolygon(points,
sizeof points /
sizeof *points);
1795 p->setPen(tb->palette.light().color());
1796 if (tb->direction != Qt::RightToLeft) {
1797 p->drawLine(0, 2, tb->rect.width() - d, 2);
1798 p->drawLine(tb->rect.width() - d - 1, 2, tb->rect.width() - 21, tb->rect.height() - 1);
1799 p->drawLine(tb->rect.width() - 20, tb->rect.height() - 1,
1800 tb->rect.width(), tb->rect.height() - 1);
1802 p->drawLine(tb->rect.width() - 1, 2, d - 1, 2);
1803 p->drawLine(d, 2, 20, tb->rect.height() - 1);
1804 p->drawLine(19, tb->rect.height() - 1,
1805 -1, tb->rect.height() - 1);
1807 p->setBrush(Qt::NoBrush);
1811#if QT_CONFIG(tabbar)
1813 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
1814 proxy()->drawControl(CE_TabBarTabShape, tab, p, widget);
1815 proxy()->drawControl(CE_TabBarTabLabel, tab, p, widget);
1818 case CE_TabBarTabShape:
1819 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
1820 QPainterStateGuard psg(p);
1821 QRect rect(tab->rect);
1822 bool selected = tab->state & State_Selected;
1823 bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
1824 int tabOverlap = onlyOne ? 0 : proxy()->pixelMetric(PM_TabBarTabOverlap, opt, widget);
1827 switch (tab->shape) {
1828 case QTabBar::TriangularNorth:
1829 rect.adjust(0, 0, 0, -tabOverlap);
1831 rect.adjust(1, 1, -1, 0);
1833 case QTabBar::TriangularSouth:
1834 rect.adjust(0, tabOverlap, 0, 0);
1836 rect.adjust(1, 0, -1, -1);
1838 case QTabBar::TriangularEast:
1839 rect.adjust(tabOverlap, 0, 0, 0);
1841 rect.adjust(0, 1, -1, -1);
1843 case QTabBar::TriangularWest:
1844 rect.adjust(0, 0, -tabOverlap, 0);
1846 rect.adjust(1, 1, 0, -1);
1853 p->setPen(QPen(tab->palette.windowText(), 0));
1855 p->setBrush(tab->palette.base());
1857 if (widget && widget->parentWidget())
1858 p->setBrush(widget->parentWidget()->palette().window());
1860 p->setBrush(tab->palette.window());
1866 switch (tab->shape) {
1867 case QTabBar::TriangularNorth:
1868 case QTabBar::TriangularSouth: {
1869 a.setPoint(0, 0, -1);
1870 a.setPoint(1, 0, 0);
1871 y = rect.height() - 2;
1873 a.setPoint(2, x++, y - 1);
1875 a.setPoint(3, x++, y++);
1876 a.setPoint(4, x, y);
1879 int right = rect.width() - 1;
1880 for (i = 0; i < 5; ++i)
1881 a.setPoint(9 - i, right - a.point(i).x(), a.point(i).y());
1882 if (tab->shape == QTabBar::TriangularNorth)
1883 for (i = 0; i < 10; ++i)
1884 a.setPoint(i, a.point(i).x(), rect.height() - 1 - a.point(i).y());
1886 a.translate(rect.left(), rect.top());
1887 p->setRenderHint(QPainter::Antialiasing);
1888 p->translate(0, 0.5);
1894 case QTabBar::TriangularEast:
1895 case QTabBar::TriangularWest: {
1896 a.setPoint(0, -1, 0);
1897 a.setPoint(1, 0, 0);
1898 x = rect.width() - 2;
1900 a.setPoint(2, x - 1, y++);
1902 a.setPoint(3, x++, y++);
1903 a.setPoint(4, x, y);
1905 int bottom = rect.height() - 1;
1906 for (i = 0; i < 5; ++i)
1907 a.setPoint(9 - i, a.point(i).x(), bottom - a.point(i).y());
1908 if (tab->shape == QTabBar::TriangularWest)
1909 for (i = 0; i < 10; ++i)
1910 a.setPoint(i, rect.width() - 1 - a.point(i).x(), a.point(i).y());
1911 a.translate(rect.left(), rect.top());
1912 p->setRenderHint(QPainter::Antialiasing);
1913 p->translate(0.5, 0);
1923 case CE_ToolBoxTabLabel:
1924 if (
const QStyleOptionToolBox *tb = qstyleoption_cast<
const QStyleOptionToolBox *>(opt)) {
1925 bool enabled = tb->state & State_Enabled;
1926 bool selected = tb->state & State_Selected;
1927 int iconExtent = proxy()->pixelMetric(QStyle::PM_SmallIconSize, tb, widget);
1928 QPixmap pm = tb->icon.pixmap(QSize(iconExtent, iconExtent), QStyleHelper::getDpr(p),
1929 enabled ? QIcon::Normal : QIcon::Disabled);
1931 QRect cr = subElementRect(QStyle::SE_ToolBoxTabContents, tb, widget);
1936 tr.adjust(4, 0, -8, 0);
1938 int iw = pm.width() / pm.devicePixelRatio() + 4;
1939 ih = pm.height()/ pm.devicePixelRatio();
1940 ir = QRect(cr.left() + 4, cr.top(), iw + 2, ih);
1941 tr = QRect(ir.right(), cr.top(), cr.width() - ir.right() - 4, cr.height());
1944 if (selected && proxy()->styleHint(QStyle::SH_ToolBox_SelectedPageTitleBold, tb, widget)) {
1950 QString txt = tb->fontMetrics.elidedText(tb->text, Qt::ElideRight, tr.width());
1953 p->drawPixmap(ir.left(), (tb->rect.height() - ih) / 2, pm);
1955 int alignment = Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic;
1956 if (!proxy()->styleHint(QStyle::SH_UnderlineShortcut, tb, widget))
1957 alignment |= Qt::TextHideMnemonic;
1958 proxy()->drawItemText(p, tr, alignment, tb->palette, enabled, txt, QPalette::ButtonText);
1960 if (!txt.isEmpty() && opt->state & State_HasFocus) {
1961 QStyleOptionFocusRect opt;
1963 opt.palette = tb->palette;
1964 opt.state = QStyle::State_None;
1965 proxy()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, p, widget);
1969 case CE_TabBarTabLabel:
1970 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
1971 QRect tr = tab->rect;
1972 bool verticalTabs = tab->shape == QTabBar::RoundedEast
1973 || tab->shape == QTabBar::RoundedWest
1974 || tab->shape == QTabBar::TriangularEast
1975 || tab->shape == QTabBar::TriangularWest;
1977 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;
1978 if (!proxy()->styleHint(SH_UnderlineShortcut, opt, widget))
1979 alignment |= Qt::TextHideMnemonic;
1981 QPainterStateGuard psg(p, QPainterStateGuard::InitialState::NoSave);
1984 int newX, newY, newRot;
1985 if (tab->shape == QTabBar::RoundedEast || tab->shape == QTabBar::TriangularEast) {
1986 newX = tr.width() + tr.x();
1991 newY = tr.y() + tr.height();
1994 QTransform m = QTransform::fromTranslate(newX, newY);
1996 p->setTransform(m,
true);
1999 d->tabLayout(tab, widget, &tr, &iconRect);
2002 if (tab->position != QStyleOptionTab::TabPosition::Moving)
2003 tr = proxy()->subElementRect(SE_TabBarTabText, opt, widget);
2005 if (!tab->icon.isNull()) {
2006 QPixmap tabIcon = tab->icon.pixmap(tab->iconSize, QStyleHelper::getDpr(p),
2007 (tab->state & State_Enabled) ? QIcon::Normal
2009 (tab->state & State_Selected) ? QIcon::On
2011 p->drawPixmap(iconRect.x(), iconRect.y(), tabIcon);
2014 proxy()->drawItemText(p, tr, alignment, tab->palette, tab->state & State_Enabled, tab->text,
2015 widget ? widget->foregroundRole() : QPalette::WindowText);
2019 if (tab->state & State_HasFocus) {
2020 const int OFFSET = 1 + pixelMetric(PM_DefaultFrameWidth, opt, widget);
2023 x1 = tab->rect.left();
2024 x2 = tab->rect.right() - 1;
2026 QStyleOptionFocusRect fropt;
2027 fropt.QStyleOption::operator=(*tab);
2028 fropt.rect.setRect(x1 + 1 + OFFSET, tab->rect.y() + OFFSET,
2029 x2 - x1 - 2*OFFSET, tab->rect.height() - 2*OFFSET);
2030 drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
2035#if QT_CONFIG(sizegrip)
2037 QPainterStateGuard psg(p);
2039 opt->rect.getRect(&x, &y, &w, &h);
2041 int sw = qMin(h, w);
2043 p->translate(0, h - w);
2045 p->translate(w - h, 0);
2052 if (
const QStyleOptionSizeGrip *sgOpt = qstyleoption_cast<
const QStyleOptionSizeGrip *>(opt))
2053 corner = sgOpt->corner;
2054 else if (opt->direction == Qt::RightToLeft)
2055 corner = Qt::BottomLeftCorner;
2057 corner = Qt::BottomRightCorner;
2059 if (corner == Qt::BottomLeftCorner) {
2061 for (
int i = 0; i < 4; ++i) {
2062 p->setPen(opt->palette.light().color());
2063 p->drawLine(x, sy - 1 , sx + 1, sw);
2064 p->setPen(opt->palette.dark().color());
2065 p->drawLine(x, sy, sx, sw);
2066 p->setPen(opt->palette.dark().color());
2067 p->drawLine(x, sy + 1, sx - 1, sw);
2071 }
else if (corner == Qt::BottomRightCorner) {
2072 for (
int i = 0; i < 4; ++i) {
2073 p->setPen(opt->palette.light().color());
2074 p->drawLine(sx - 1, sw, sw, sy - 1);
2075 p->setPen(opt->palette.dark().color());
2076 p->drawLine(sx, sw, sw, sy);
2077 p->setPen(opt->palette.dark().color());
2078 p->drawLine(sx + 1, sw, sw, sy + 1);
2082 }
else if (corner == Qt::TopRightCorner) {
2084 for (
int i = 0; i < 4; ++i) {
2085 p->setPen(opt->palette.light().color());
2086 p->drawLine(sx - 1, y, sw, sy + 1);
2087 p->setPen(opt->palette.dark().color());
2088 p->drawLine(sx, y, sw, sy);
2089 p->setPen(opt->palette.dark().color());
2090 p->drawLine(sx + 1, y, sw, sy - 1);
2094 }
else if (corner == Qt::TopLeftCorner) {
2095 for (
int i = 0; i < 4; ++i) {
2096 p->setPen(opt->palette.light().color());
2097 p->drawLine(x, sy - 1, sx - 1, y);
2098 p->setPen(opt->palette.dark().color());
2099 p->drawLine(x, sy, sx, y);
2100 p->setPen(opt->palette.dark().color());
2101 p->drawLine(x, sy + 1, sx + 1, y);
2108#if QT_CONFIG(rubberband)
2109 case CE_RubberBand: {
2110 if (
const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<
const QStyleOptionRubberBand *>(opt)) {
2111 QPixmap tiledPixmap(16, 16);
2112 QPainter pixmapPainter(&tiledPixmap);
2113 pixmapPainter.setPen(Qt::NoPen);
2114 pixmapPainter.setBrush(Qt::Dense4Pattern);
2115 pixmapPainter.setBackground(QBrush(opt->palette.base()));
2116 pixmapPainter.setBackgroundMode(Qt::OpaqueMode);
2117 pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height());
2118 pixmapPainter.end();
2120 tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage());
2122 QPainterStateGuard psg(p);
2123 QRect r = opt->rect;
2124 QStyleHintReturnMask mask;
2125 if (proxy()->styleHint(QStyle::SH_RubberBand_Mask, opt, widget, &mask))
2126 p->setClipRegion(mask.region);
2127 p->drawTiledPixmap(r.x(), r.y(), r.width(), r.height(), tiledPixmap);
2128 p->setPen(opt->palette.color(QPalette::Active, QPalette::WindowText));
2129 p->setBrush(Qt::NoBrush);
2130 p->drawRect(r.adjusted(0, 0, -1, -1));
2131 if (rbOpt->shape == QRubberBand::Rectangle)
2132 p->drawRect(r.adjusted(3, 3, -4, -4));
2136#if QT_CONFIG(dockwidget)
2137 case CE_DockWidgetTitle:
2138 if (
const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<
const QStyleOptionDockWidget *>(opt)) {
2139 QRect r = dwOpt->rect.adjusted(0, 0, -1, -1);
2140 if (dwOpt->movable) {
2141 p->setPen(dwOpt->palette.color(QPalette::Dark));
2145 if (!dwOpt->title.isEmpty()) {
2146 const bool verticalTitleBar = dwOpt->verticalTitleBar;
2148 QPainterStateGuard psg(p, QPainterStateGuard::InitialState::NoSave);
2149 if (verticalTitleBar) {
2153 p->translate(r.left(), r.top() + r.width());
2155 p->translate(-r.left(), -r.top());
2158 const int indent = p->fontMetrics().descent();
2159 proxy()->drawItemText(p, r.adjusted(indent + 1, 1, -indent - 1, -1),
2160 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextHideMnemonic, dwOpt->palette,
2161 dwOpt->state & State_Enabled, dwOpt->title,
2162 QPalette::WindowText);
2168 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
2169 QPainterStateGuard psg(p);
2170 p->setClipRect(opt->rect);
2171 proxy()->drawControl(CE_HeaderSection, header, p, widget);
2173 QStyleOptionHeaderV2 subopt;
2174 QStyleOptionHeader &v1Copy = subopt;
2175 if (
auto v2 = qstyleoption_cast<
const QStyleOptionHeaderV2 *>(opt))
2179 subopt.rect = subElementRect(SE_HeaderLabel, header, widget);
2180 if (subopt.rect.isValid())
2181 proxy()->drawControl(CE_HeaderLabel, &subopt, p, widget);
2182 if (header->sortIndicator != QStyleOptionHeader::None) {
2183 subopt.rect = subElementRect(SE_HeaderArrow, opt, widget);
2184 proxy()->drawPrimitive(PE_IndicatorHeaderArrow, &subopt, p, widget);
2189 p->fillRect(opt->rect, opt->palette.windowText());
2191 case CE_HeaderSection:
2192 qDrawShadePanel(p, opt->rect, opt->palette,
2193 opt->state & State_Sunken, 1,
2194 &opt->palette.brush(QPalette::Button));
2196 case CE_HeaderEmptyArea:
2197 p->fillRect(opt->rect, opt->palette.window());
2199#if QT_CONFIG(combobox)
2200 case CE_ComboBoxLabel:
2201 if (
const QStyleOptionComboBox *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
2202 QRect editRect = proxy()->subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget);
2203 QPainterStateGuard psg(p);
2204 p->setClipRect(editRect);
2205 if (!cb->currentIcon.isNull()) {
2206 QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal
2208 QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, QStyleHelper::getDpr(p), mode);
2209 QRect iconRect(editRect);
2210 iconRect.setWidth(cb->iconSize.width() + 4);
2211 iconRect = alignedRect(cb->direction,
2212 Qt::AlignLeft | Qt::AlignVCenter,
2213 iconRect.size(), editRect);
2215 p->fillRect(iconRect, opt->palette.brush(QPalette::Base));
2216 proxy()->drawItemPixmap(p, iconRect, Qt::AlignCenter, pixmap);
2218 if (cb->direction == Qt::RightToLeft)
2219 editRect.translate(-4 - cb->iconSize.width(), 0);
2221 editRect.translate(cb->iconSize.width() + 4, 0);
2223 if (!cb->currentText.isEmpty() && !cb->editable) {
2225 proxy()->drawItemText(p, editRect.adjusted(2, 0, -2, 0),
2226 visualAlignment(cb->direction, cb->textAlignment),
2227 cb->palette, cb->state & State_Enabled, cb->currentText);
2232#if QT_CONFIG(toolbar)
2234 if (
const QStyleOptionToolBar *toolBar = qstyleoption_cast<
const QStyleOptionToolBar *>(opt)) {
2236 QStyleOptionFrame frame;
2237 frame.QStyleOption::operator=(*toolBar);
2238 frame.lineWidth = toolBar->lineWidth;
2239 frame.midLineWidth = toolBar->midLineWidth;
2240 proxy()->drawPrimitive(PE_PanelToolBar, opt, p, widget);
2242 if (widget && qobject_cast<QToolBar *>(widget->parentWidget()))
2244 qDrawShadePanel(p, toolBar->rect, toolBar->palette,
false, toolBar->lineWidth,
2245 &toolBar->palette.brush(QPalette::Button));
2249 case CE_ColumnViewGrip: {
2251 QLinearGradient g(0, 0, opt->rect.width(), 0);
2252 g.setColorAt(0, opt->palette.color(QPalette::Active, QPalette::Mid));
2253 g.setColorAt(0.5, Qt::white);
2254 p->fillRect(QRect(0, 0, opt->rect.width(), opt->rect.height()), g);
2258 pen.setWidth(opt->rect.width()/20);
2259 pen.setColor(opt->palette.color(QPalette::Active, QPalette::Dark));
2262 int line1starting = opt->rect.width()*8 / 20;
2263 int line2starting = opt->rect.width()*13 / 20;
2264 int top = opt->rect.height()*20/75;
2265 int bottom = opt->rect.height() - 1 - top;
2266 p->drawLine(line1starting, top, line1starting, bottom);
2267 p->drawLine(line2starting, top, line2starting, bottom);
2271#if QT_CONFIG(itemviews)
2272 case CE_ItemViewItem:
2273 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
2274 QPainterStateGuard psg(p);
2276 const QRegion clipRegion = p->hasClipping() ? (p->clipRegion() & opt->rect) : opt->rect;
2277 p->setClipRegion(clipRegion);
2279 QRect checkRect = proxy()->subElementRect(SE_ItemViewItemCheckIndicator, vopt, widget);
2280 QRect iconRect = proxy()->subElementRect(SE_ItemViewItemDecoration, vopt, widget);
2281 QRect textRect = proxy()->subElementRect(SE_ItemViewItemText, vopt, widget);
2284 proxy()->drawPrimitive(PE_PanelItemViewItem, opt, p, widget);
2287 if (vopt->features & QStyleOptionViewItem::HasCheckIndicator) {
2288 QStyleOptionViewItem option(*vopt);
2289 option.rect = checkRect;
2290 option.state = option.state & ~QStyle::State_HasFocus;
2292 switch (vopt->checkState) {
2294 option.state |= QStyle::State_Off;
2296 case Qt::PartiallyChecked:
2297 option.state |= QStyle::State_NoChange;
2300 option.state |= QStyle::State_On;
2303 proxy()->drawPrimitive(QStyle::PE_IndicatorItemViewItemCheck, &option, p, widget);
2307 QIcon::Mode mode = QIcon::Normal;
2308 if (!(vopt->state & QStyle::State_Enabled))
2309 mode = QIcon::Disabled;
2310 else if (vopt->state & QStyle::State_Selected)
2311 mode = QIcon::Selected;
2312 QIcon::State state = vopt->state & QStyle::State_Open ? QIcon::On : QIcon::Off;
2313 vopt->icon.paint(p, iconRect, vopt->decorationAlignment, mode, state);
2316 if (!vopt->text.isEmpty()) {
2317 QPalette::ColorGroup cg = vopt->state & QStyle::State_Enabled
2318 ? QPalette::Normal : QPalette::Disabled;
2319 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))
2320 cg = QPalette::Inactive;
2322 if (vopt->state & QStyle::State_Selected) {
2323 p->setPen(vopt->palette.color(cg, QPalette::HighlightedText));
2325 p->setPen(vopt->palette.color(cg, QPalette::Text));
2327 if (vopt->state & QStyle::State_Editing) {
2328 p->setPen(vopt->palette.color(cg, QPalette::Text));
2329 p->drawRect(textRect.adjusted(0, 0, -1, -1));
2332 d->viewItemDrawText(p, vopt, textRect);
2336 if (vopt->state & QStyle::State_HasFocus) {
2337 QStyleOptionFocusRect o;
2338 o.QStyleOption::operator=(*vopt);
2339 o.rect = proxy()->subElementRect(SE_ItemViewItemFocusRect, vopt, widget);
2340 o.state |= QStyle::State_KeyboardFocusChange;
2341 o.state |= QStyle::State_Item;
2342 QPalette::ColorGroup cg = (vopt->state & QStyle::State_Enabled)
2343 ? QPalette::Normal : QPalette::Disabled;
2344 o.backgroundColor = vopt->palette.color(cg, (vopt->state & QStyle::State_Selected)
2345 ? QPalette::Highlight : QPalette::Window);
2346 proxy()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, p, widget);
2353 case CE_ShapedFrame:
2354 if (
const QStyleOptionFrame *f = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
2355 int frameShape = f->frameShape;
2356 int frameShadow = QFrame::Plain;
2357 if (f->state & QStyle::State_Sunken) {
2358 frameShadow = QFrame::Sunken;
2359 }
else if (f->state & QStyle::State_Raised) {
2360 frameShadow = QFrame::Raised;
2363 int lw = f->lineWidth;
2364 int mlw = f->midLineWidth;
2365 QPalette::ColorRole foregroundRole = QPalette::WindowText;
2367 foregroundRole = widget->foregroundRole();
2369 switch (frameShape) {
2371 if (frameShadow == QFrame::Plain) {
2372 qDrawPlainRect(p, f->rect, f->palette.color(foregroundRole), lw);
2374 qDrawShadeRect(p, f->rect, f->palette, frameShadow == QFrame::Sunken, lw, mlw);
2377 case QFrame::StyledPanel:
2381 widget->style()->drawPrimitive(QStyle::PE_Frame, opt, p, widget);
2383 proxy()->drawPrimitive(QStyle::PE_Frame, opt, p, widget);
2387 if (frameShadow == QFrame::Plain) {
2388 qDrawPlainRect(p, f->rect, f->palette.color(foregroundRole), lw);
2390 qDrawShadePanel(p, f->rect, f->palette, frameShadow == QFrame::Sunken, lw);
2393 case QFrame::WinPanel:
2394 if (frameShadow == QFrame::Plain) {
2395 qDrawPlainRect(p, f->rect, f->palette.color(foregroundRole), lw);
2397 qDrawWinPanel(p, f->rect, f->palette, frameShadow == QFrame::Sunken);
2401 case QFrame::VLine: {
2403 if (frameShape == QFrame::HLine) {
2404 p1 = QPoint(opt->rect.x(), opt->rect.y() + opt->rect.height() / 2);
2405 p2 = QPoint(opt->rect.x() + opt->rect.width(), p1.y());
2407 p1 = QPoint(opt->rect.x() + opt->rect.width() / 2, opt->rect.y());
2408 p2 = QPoint(p1.x(), p1.y() + opt->rect.height());
2410 if (frameShadow == QFrame::Plain) {
2411 QPen oldPen = p->pen();
2412 p->setPen(QPen(opt->palette.brush(foregroundRole), lw));
2413 p->drawLine(p1, p2);
2416 qDrawShadeLine(p, p1, p2, f->palette, frameShadow == QFrame::Sunken, lw, mlw);
2427#if !QT_CONFIG(tabbar) && !QT_CONFIG(itemviews)
2435QRect QCommonStyle::subElementRect(SubElement sr,
const QStyleOption *opt,
2436 const QWidget *widget)
const
2438 Q_D(
const QCommonStyle);
2441 case SE_PushButtonContents:
2442 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
2444 dx1 = proxy()->pixelMetric(PM_DefaultFrameWidth, btn, widget);
2445 if (btn->features & QStyleOptionButton::AutoDefaultButton)
2446 dx1 += proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
2448 r.setRect(opt->rect.x() + dx1, opt->rect.y() + dx1, opt->rect.width() - dx2,
2449 opt->rect.height() - dx2);
2450 r = visualRect(opt->direction, opt->rect, r);
2453 case SE_PushButtonFocusRect:
2454 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
2455 int dbw1 = 0, dbw2 = 0;
2456 if (btn->features & QStyleOptionButton::AutoDefaultButton){
2457 dbw1 = proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
2461 int dfw1 = proxy()->pixelMetric(PM_DefaultFrameWidth, btn, widget) + 1,
2464 r.setRect(btn->rect.x() + dfw1 + dbw1, btn->rect.y() + dfw1 + dbw1,
2465 btn->rect.width() - dfw2 - dbw2, btn->rect.height()- dfw2 - dbw2);
2466 r = visualRect(opt->direction, opt->rect, r);
2469 case SE_PushButtonBevel:
2472 r = visualRect(opt->direction, opt->rect, r);
2475 case SE_CheckBoxIndicator:
2477 int h = proxy()->pixelMetric(PM_IndicatorHeight, opt, widget);
2478 r.setRect(opt->rect.x(), opt->rect.y() + ((opt->rect.height() - h) / 2),
2479 proxy()->pixelMetric(PM_IndicatorWidth, opt, widget), h);
2480 r = visualRect(opt->direction, opt->rect, r);
2484 case SE_CheckBoxContents:
2487 QRect ir = visualRect(opt->direction, opt->rect,
2488 subElementRect(SE_CheckBoxIndicator, opt, widget));
2489 int spacing = proxy()->pixelMetric(PM_CheckBoxLabelSpacing, opt, widget);
2490 r.setRect(ir.right() + spacing, opt->rect.y(), opt->rect.width() - ir.width() - spacing,
2491 opt->rect.height());
2492 r = visualRect(opt->direction, opt->rect, r);
2496 case SE_CheckBoxFocusRect:
2497 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
2498 if (btn->icon.isNull() && btn->text.isEmpty()) {
2499 r = subElementRect(SE_CheckBoxIndicator, opt, widget);
2500 r.adjust(1, 1, -1, -1);
2504 QRect cr = visualRect(btn->direction, btn->rect,
2505 subElementRect(SE_CheckBoxContents, btn, widget));
2507 QRect iconRect, textRect;
2508 if (!btn->text.isEmpty()) {
2509 textRect = itemTextRect(opt->fontMetrics, cr, Qt::AlignAbsolute | Qt::AlignLeft
2510 | Qt::AlignVCenter | Qt::TextShowMnemonic,
2511 btn->state & State_Enabled, btn->text);
2513 if (!btn->icon.isNull()) {
2514 iconRect = itemPixmapRect(cr, Qt::AlignAbsolute | Qt::AlignLeft | Qt::AlignVCenter
2515 | Qt::TextShowMnemonic,
2516 btn->icon.pixmap(btn->iconSize, QStyleHelper::getDpr(widget), QIcon::Normal));
2517 if (!textRect.isEmpty())
2518 textRect.translate(iconRect.right() + 4, 0);
2520 r = iconRect | textRect;
2521 r.adjust(-3, -2, 3, 2);
2522 r = r.intersected(btn->rect);
2523 r = visualRect(btn->direction, btn->rect, r);
2527 case SE_RadioButtonIndicator:
2529 int h = proxy()->pixelMetric(PM_ExclusiveIndicatorHeight, opt, widget);
2530 r.setRect(opt->rect.x(), opt->rect.y() + ((opt->rect.height() - h) / 2),
2531 proxy()->pixelMetric(PM_ExclusiveIndicatorWidth, opt, widget), h);
2532 r = visualRect(opt->direction, opt->rect, r);
2536 case SE_RadioButtonContents:
2538 QRect ir = visualRect(opt->direction, opt->rect,
2539 subElementRect(SE_RadioButtonIndicator, opt, widget));
2540 int spacing = proxy()->pixelMetric(PM_RadioButtonLabelSpacing, opt, widget);
2541 r.setRect(ir.left() + ir.width() + spacing, opt->rect.y(), opt->rect.width() - ir.width() - spacing,
2542 opt->rect.height());
2543 r = visualRect(opt->direction, opt->rect, r);
2547 case SE_RadioButtonFocusRect:
2548 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
2549 if (btn->icon.isNull() && btn->text.isEmpty()) {
2550 r = subElementRect(SE_RadioButtonIndicator, opt, widget);
2551 r.adjust(1, 1, -1, -1);
2554 QRect cr = visualRect(btn->direction, btn->rect,
2555 subElementRect(SE_RadioButtonContents, opt, widget));
2557 QRect iconRect, textRect;
2558 if (!btn->text.isEmpty()){
2559 textRect = itemTextRect(opt->fontMetrics, cr, Qt::AlignAbsolute | Qt::AlignLeft | Qt::AlignVCenter
2560 | Qt::TextShowMnemonic, btn->state & State_Enabled, btn->text);
2562 if (!btn->icon.isNull()) {
2563 iconRect = itemPixmapRect(cr, Qt::AlignAbsolute | Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic,
2564 btn->icon.pixmap(btn->iconSize, QStyleHelper::getDpr(widget), QIcon::Normal));
2565 if (!textRect.isEmpty())
2566 textRect.translate(iconRect.right() + 4, 0);
2568 r = iconRect | textRect;
2569 r.adjust(-3, -2, 3, 2);
2570 r = r.intersected(btn->rect);
2571 r = visualRect(btn->direction, btn->rect, r);
2574#if QT_CONFIG(slider)
2575 case SE_SliderFocusRect:
2576 if (
const QStyleOptionSlider *slider = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
2577 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider, widget);
2578 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
2579 if (slider->orientation == Qt::Horizontal)
2580 r.setRect(0, tickOffset - 1, slider->rect.width(), thickness + 2);
2582 r.setRect(tickOffset - 1, 0, thickness + 2, slider->rect.height());
2583 r = r.intersected(slider->rect);
2584 r = visualRect(opt->direction, opt->rect, r);
2588#if QT_CONFIG(progressbar)
2589 case SE_ProgressBarGroove:
2590 case SE_ProgressBarContents:
2591 case SE_ProgressBarLabel:
2592 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
2594 const bool vertical = !(pb->state & QStyle::State_Horizontal);
2596 if (pb->textVisible)
2597 textw = qMax(pb->fontMetrics.horizontalAdvance(pb->text), pb->fontMetrics.horizontalAdvance(
"100%"_L1)) + 6;
2600 if ((pb->textAlignment & Qt::AlignCenter) == 0) {
2601 if (sr != SE_ProgressBarLabel)
2602 r.setCoords(pb->rect.left(), pb->rect.top(),
2603 pb->rect.right() - textw, pb->rect.bottom());
2605 r.setCoords(pb->rect.right() - textw, pb->rect.top(),
2606 pb->rect.right(), pb->rect.bottom());
2610 r = visualRect(pb->direction, pb->rect, r);
2614#if QT_CONFIG(combobox)
2615 case SE_ComboBoxFocusRect:
2616 if (
const QStyleOptionComboBox *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
2617 int margin = cb->frame ? 3 : 0;
2618 r.setRect(opt->rect.left() + margin, opt->rect.top() + margin,
2619 opt->rect.width() - 2*margin - 16, opt->rect.height() - 2*margin);
2620 r = visualRect(opt->direction, opt->rect, r);
2624#if QT_CONFIG(toolbox)
2625 case SE_ToolBoxTabContents:
2627 r.adjust(0, 0, -30, 0);
2630 case SE_HeaderLabel: {
2631 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget);
2632 r.setRect(opt->rect.x() + margin, opt->rect.y() + margin,
2633 opt->rect.width() - margin * 2, opt->rect.height() - margin * 2);
2635 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
2637 if (header->sortIndicator != QStyleOptionHeader::None) {
2638 if (opt->state & State_Horizontal)
2639 r.setWidth(r.width() - (opt->rect.height() / 2) - (margin * 2));
2641 r.setHeight(r.height() - (opt->rect.width() / 2) - (margin * 2));
2644 r = visualRect(opt->direction, opt->rect, r);
2646 case SE_HeaderArrow: {
2647 int h = opt->rect.height();
2648 int w = opt->rect.width();
2649 int x = opt->rect.x();
2650 int y = opt->rect.y();
2651 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget);
2653 if (opt->state & State_Horizontal) {
2654 int horiz_size = h / 2;
2655 r.setRect(x + w - margin * 2 - horiz_size, y + 5,
2656 horiz_size, h - margin * 2 - 5);
2658 int vert_size = w / 2;
2659 r.setRect(x + 5, y + h - margin * 2 - vert_size,
2660 w - margin * 2 - 5, vert_size);
2662 r = visualRect(opt->direction, opt->rect, r);
2665 case SE_RadioButtonClickRect:
2666 r = subElementRect(SE_RadioButtonFocusRect, opt, widget);
2667 r |= subElementRect(SE_RadioButtonIndicator, opt, widget);
2669 case SE_CheckBoxClickRect:
2670 r = subElementRect(SE_CheckBoxFocusRect, opt, widget);
2671 r |= subElementRect(SE_CheckBoxIndicator, opt, widget);
2673#if QT_CONFIG(tabwidget)
2674 case SE_TabWidgetTabBar:
2675 if (
const QStyleOptionTabWidgetFrame *twf
2676 = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
2677 r.setSize(twf->tabBarSize);
2678 const uint alingMask = Qt::AlignLeft | Qt::AlignRight | Qt::AlignHCenter;
2679 switch (twf->shape) {
2680 case QTabBar::RoundedNorth:
2681 case QTabBar::TriangularNorth:
2684 r.setWidth(qMin(r.width(), twf->rect.width()
2685 - twf->leftCornerWidgetSize.width()
2686 - twf->rightCornerWidgetSize.width()));
2687 switch (proxy()->styleHint(SH_TabBar_Alignment, twf, widget) & alingMask) {
2690 r.moveTopLeft(QPoint(twf->leftCornerWidgetSize.width(), 0));
2692 case Qt::AlignHCenter:
2693 r.moveTopLeft(QPoint(twf->rect.center().x() - qRound(r.width() / 2.0f)
2694 + (twf->leftCornerWidgetSize.width() / 2)
2695 - (twf->rightCornerWidgetSize.width() / 2), 0));
2697 case Qt::AlignRight:
2698 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width()
2699 - twf->rightCornerWidgetSize.width(), 0));
2702 r = visualRect(twf->direction, twf->rect, r);
2704 case QTabBar::RoundedSouth:
2705 case QTabBar::TriangularSouth:
2706 r.setWidth(qMin(r.width(), twf->rect.width()
2707 - twf->leftCornerWidgetSize.width()
2708 - twf->rightCornerWidgetSize.width()));
2709 switch (proxy()->styleHint(SH_TabBar_Alignment, twf, widget) & alingMask) {
2712 r.moveTopLeft(QPoint(twf->leftCornerWidgetSize.width(),
2713 twf->rect.height() - twf->tabBarSize.height()));
2715 case Qt::AlignHCenter:
2716 r.moveTopLeft(QPoint(twf->rect.center().x() - qRound(r.width() / 2.0f)
2717 + (twf->leftCornerWidgetSize.width() / 2)
2718 - (twf->rightCornerWidgetSize.width() / 2),
2719 twf->rect.height() - twf->tabBarSize.height()));
2721 case Qt::AlignRight:
2722 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width()
2723 - twf->rightCornerWidgetSize.width(),
2724 twf->rect.height() - twf->tabBarSize.height()));
2727 r = visualRect(twf->direction, twf->rect, r);
2729 case QTabBar::RoundedEast:
2730 case QTabBar::TriangularEast:
2731 r.setHeight(qMin(r.height(), twf->rect.height()
2732 - twf->leftCornerWidgetSize.height()
2733 - twf->rightCornerWidgetSize.height()));
2734 switch (proxy()->styleHint(SH_TabBar_Alignment, twf, widget) & alingMask) {
2737 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width(),
2738 twf->leftCornerWidgetSize.height()));
2740 case Qt::AlignHCenter:
2741 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width(),
2742 twf->rect.center().y() - r.height() / 2));
2744 case Qt::AlignRight:
2745 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width(),
2746 twf->rect.height() - twf->tabBarSize.height()
2747 - twf->rightCornerWidgetSize.height()));
2751 case QTabBar::RoundedWest:
2752 case QTabBar::TriangularWest:
2753 r.setHeight(qMin(r.height(), twf->rect.height()
2754 - twf->leftCornerWidgetSize.height()
2755 - twf->rightCornerWidgetSize.height()));
2756 switch (proxy()->styleHint(SH_TabBar_Alignment, twf, widget) & alingMask) {
2759 r.moveTopLeft(QPoint(0, twf->leftCornerWidgetSize.height()));
2761 case Qt::AlignHCenter:
2762 r.moveTopLeft(QPoint(0, twf->rect.center().y() - r.height() / 2));
2764 case Qt::AlignRight:
2765 r.moveTopLeft(QPoint(0, twf->rect.height() - twf->tabBarSize.height()
2766 - twf->rightCornerWidgetSize.height()));
2773 case SE_TabWidgetTabPane:
2774 case SE_TabWidgetTabContents:
2775 if (
const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
2776 QStyleOptionTab tabopt;
2777 tabopt.shape = twf->shape;
2778 int overlap = proxy()->pixelMetric(PM_TabBarBaseOverlap, &tabopt, widget);
2779 if (twf->lineWidth == 0)
2781 switch (twf->shape) {
2782 case QTabBar::RoundedNorth:
2783 case QTabBar::TriangularNorth:
2784 r = QRect(QPoint(0,qMax(twf->tabBarSize.height() - overlap, 0)),
2785 QSize(twf->rect.width(), qMin(twf->rect.height() - twf->tabBarSize.height() + overlap, twf->rect.height())));
2787 case QTabBar::RoundedSouth:
2788 case QTabBar::TriangularSouth:
2789 r = QRect(QPoint(0,0), QSize(twf->rect.width(), qMin(twf->rect.height() - twf->tabBarSize.height() + overlap, twf->rect.height())));
2791 case QTabBar::RoundedEast:
2792 case QTabBar::TriangularEast:
2793 r = QRect(QPoint(0, 0), QSize(qMin(twf->rect.width() - twf->tabBarSize.width() + overlap, twf->rect.width()), twf->rect.height()));
2795 case QTabBar::RoundedWest:
2796 case QTabBar::TriangularWest:
2797 r = QRect(QPoint(qMax(twf->tabBarSize.width() - overlap, 0), 0),
2798 QSize(qMin(twf->rect.width() - twf->tabBarSize.width() + overlap, twf->rect.width()), twf->rect.height()));
2801 if (sr == SE_TabWidgetTabContents && twf->lineWidth > 0)
2802 r.adjust(2, 2, -2, -2);
2805 case SE_TabWidgetLeftCorner:
2806 if (
const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
2807 QRect paneRect = subElementRect(SE_TabWidgetTabPane, twf, widget);
2808 switch (twf->shape) {
2809 case QTabBar::RoundedNorth:
2810 case QTabBar::TriangularNorth:
2811 r = QRect(QPoint(paneRect.x(), paneRect.y() - twf->leftCornerWidgetSize.height()),
2812 twf->leftCornerWidgetSize);
2814 case QTabBar::RoundedSouth:
2815 case QTabBar::TriangularSouth:
2816 r = QRect(QPoint(paneRect.x(), paneRect.height()), twf->leftCornerWidgetSize);
2821 r = visualRect(twf->direction, twf->rect, r);
2824 case SE_TabWidgetRightCorner:
2825 if (
const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
2826 QRect paneRect = subElementRect(SE_TabWidgetTabPane, twf, widget);
2827 switch (twf->shape) {
2828 case QTabBar::RoundedNorth:
2829 case QTabBar::TriangularNorth:
2830 r = QRect(QPoint(paneRect.width() - twf->rightCornerWidgetSize.width(),
2831 paneRect.y() - twf->rightCornerWidgetSize.height()),
2832 twf->rightCornerWidgetSize);
2834 case QTabBar::RoundedSouth:
2835 case QTabBar::TriangularSouth:
2836 r = QRect(QPoint(paneRect.width() - twf->rightCornerWidgetSize.width(),
2837 paneRect.height()), twf->rightCornerWidgetSize);
2842 r = visualRect(twf->direction, twf->rect, r);
2845 case SE_TabBarTabText:
2846 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
2847 QRect dummyIconRect;
2848 d->tabLayout(tab, widget, &r, &dummyIconRect);
2851 case SE_TabBarTabLeftButton:
2852 case SE_TabBarTabRightButton:
2853 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
2854 bool selected = tab->state & State_Selected;
2855 int verticalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab, widget);
2856 int horizontalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab, widget);
2857 int hpadding = proxy()->pixelMetric(QStyle::PM_TabBarTabHSpace, opt, widget) / 2;
2858 hpadding = qMax(hpadding, 4);
2860 bool verticalTabs = tab->shape == QTabBar::RoundedEast
2861 || tab->shape == QTabBar::RoundedWest
2862 || tab->shape == QTabBar::TriangularEast
2863 || tab->shape == QTabBar::TriangularWest;
2865 QRect tr = tab->rect;
2866 if (tab->shape == QTabBar::RoundedSouth || tab->shape == QTabBar::TriangularSouth)
2867 verticalShift = -verticalShift;
2869 qSwap(horizontalShift, verticalShift);
2870 horizontalShift *= -1;
2871 verticalShift *= -1;
2873 if (tab->shape == QTabBar::RoundedWest || tab->shape == QTabBar::TriangularWest)
2874 horizontalShift = -horizontalShift;
2876 tr.adjust(0, 0, horizontalShift, verticalShift);
2879 tr.setBottom(tr.bottom() - verticalShift);
2880 tr.setRight(tr.right() - horizontalShift);
2883 QSize size = (sr == SE_TabBarTabLeftButton) ? tab->leftButtonSize : tab->rightButtonSize;
2884 int w = size.width();
2885 int h = size.height();
2886 int midHeight =
static_cast<
int>(qCeil(
float(tr.height() - h) / 2));
2887 int midWidth = ((tr.width() - w) / 2);
2889 bool atTheTop =
true;
2890 switch (tab->shape) {
2891 case QTabBar::RoundedWest:
2892 case QTabBar::TriangularWest:
2893 atTheTop = (sr == SE_TabBarTabLeftButton);
2895 case QTabBar::RoundedEast:
2896 case QTabBar::TriangularEast:
2897 atTheTop = (sr == SE_TabBarTabRightButton);
2900 if (sr == SE_TabBarTabLeftButton)
2901 r = QRect(tab->rect.x() + hpadding, midHeight, w, h);
2903 r = QRect(tab->rect.right() - w - hpadding, midHeight, w, h);
2904 r = visualRect(tab->direction, tab->rect, r);
2908 r = QRect(midWidth, tr.y() + tab->rect.height() - hpadding - h, w, h);
2910 r = QRect(midWidth, tr.y() + hpadding, w, h);
2916#if QT_CONFIG(tabbar)
2917 case SE_TabBarTearIndicator:
2918 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
2919 switch (tab->shape) {
2920 case QTabBar::RoundedNorth:
2921 case QTabBar::TriangularNorth:
2922 case QTabBar::RoundedSouth:
2923 case QTabBar::TriangularSouth:
2924 r.setRect(tab->rect.left(), tab->rect.top(), 8, opt->rect.height());
2926 case QTabBar::RoundedWest:
2927 case QTabBar::TriangularWest:
2928 case QTabBar::RoundedEast:
2929 case QTabBar::TriangularEast:
2930 r.setRect(tab->rect.left(), tab->rect.top(), opt->rect.width(), 8);
2935 r = visualRect(opt->direction, opt->rect, r);
2938 case SE_TabBarScrollLeftButton: {
2939 const bool vertical = opt->rect.width() < opt->rect.height();
2940 const Qt::LayoutDirection ld = widget->layoutDirection();
2941 const int buttonWidth = proxy()->pixelMetric(QStyle::PM_TabBarScrollButtonWidth,
nullptr, widget);
2942 const int buttonOverlap = proxy()->pixelMetric(QStyle::PM_TabBar_ScrollButtonOverlap,
nullptr, widget);
2944 r = vertical ? QRect(0, opt->rect.height() - (buttonWidth * 2) + buttonOverlap, opt->rect.width(), buttonWidth)
2945 : QStyle::visualRect(ld, opt->rect, QRect(opt->rect.width() - (buttonWidth * 2) + buttonOverlap, 0, buttonWidth, opt->rect.height()));
2947 case SE_TabBarScrollRightButton: {
2948 const bool vertical = opt->rect.width() < opt->rect.height();
2949 const Qt::LayoutDirection ld = widget->layoutDirection();
2950 const int buttonWidth = proxy()->pixelMetric(QStyle::PM_TabBarScrollButtonWidth,
nullptr, widget);
2952 r = vertical ? QRect(0, opt->rect.height() - buttonWidth, opt->rect.width(), buttonWidth)
2953 : QStyle::visualRect(ld, opt->rect, QRect(opt->rect.width() - buttonWidth, 0, buttonWidth, opt->rect.height()));
2956 case SE_TreeViewDisclosureItem:
2959 case SE_LineEditContents:
2960 if (
const QStyleOptionFrame *f = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
2961 r = f->rect.adjusted(f->lineWidth, f->lineWidth, -f->lineWidth, -f->lineWidth);
2962 r = visualRect(opt->direction, opt->rect, r);
2965 case SE_FrameContents:
2966 if (
const QStyleOptionFrame *f = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
2967 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, f, widget);
2968 r = opt->rect.adjusted(fw, fw, -fw, -fw);
2969 r = visualRect(opt->direction, opt->rect, r);
2972 case SE_ShapedFrameContents:
2973 if (
const QStyleOptionFrame *f = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
2974 int frameShape = f->frameShape;
2975 int frameShadow = QFrame::Plain;
2976 if (f->state & QStyle::State_Sunken) {
2977 frameShadow = QFrame::Sunken;
2978 }
else if (f->state & QStyle::State_Raised) {
2979 frameShadow = QFrame::Raised;
2984 switch (frameShape) {
2985 case QFrame::NoFrame:
2992 switch (frameShadow) {
2994 frameWidth = f->lineWidth;
2996 case QFrame::Raised:
2997 case QFrame::Sunken:
2998 frameWidth = (
short)(f->lineWidth*2 + f->midLineWidth);
3003 case QFrame::StyledPanel:
3007 return widget->style()->subElementRect(QStyle::SE_FrameContents, opt, widget);
3009 return subElementRect(QStyle::SE_FrameContents, opt, widget);
3011 case QFrame::WinPanel:
3016 switch (frameShadow) {
3018 case QFrame::Raised:
3019 case QFrame::Sunken:
3020 frameWidth = f->lineWidth;
3025 r = f->rect.adjusted(frameWidth, frameWidth, -frameWidth, -frameWidth);
3028#if QT_CONFIG(dockwidget)
3029 case SE_DockWidgetCloseButton:
3030 case SE_DockWidgetFloatButton:
3031 case SE_DockWidgetTitleBarText:
3032 case SE_DockWidgetIcon: {
3033 int iconSize = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
3034 int buttonMargin = proxy()->pixelMetric(PM_DockWidgetTitleBarButtonMargin, opt, widget);
3035 int margin = proxy()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, opt, widget);
3036 QRect rect = opt->rect;
3038 const QStyleOptionDockWidget *dwOpt
3039 = qstyleoption_cast<
const QStyleOptionDockWidget*>(opt);
3040 bool canClose = dwOpt ==
nullptr ?
true : dwOpt->closable;
3041 bool canFloat = dwOpt ==
nullptr ?
false : dwOpt->floatable;
3043 const bool verticalTitleBar = dwOpt && dwOpt->verticalTitleBar;
3048 if (verticalTitleBar)
3049 rect = rect.transposed();
3053 int right = rect.right();
3054 int left = rect.left();
3058 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarCloseButton,
3059 opt, widget).actualSize(QSize(iconSize, iconSize));
3060 sz += QSize(buttonMargin, buttonMargin);
3061 if (verticalTitleBar)
3062 sz = sz.transposed();
3063 closeRect = QRect(right - sz.width(),
3064 rect.center().y() - sz.height()/2,
3065 sz.width(), sz.height());
3066 right = closeRect.left() - 1;
3068 if (sr == SE_DockWidgetCloseButton) {
3075 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarNormalButton,
3076 opt, widget).actualSize(QSize(iconSize, iconSize));
3077 sz += QSize(buttonMargin, buttonMargin);
3078 if (verticalTitleBar)
3079 sz = sz.transposed();
3080 floatRect = QRect(right - sz.width(),
3081 rect.center().y() - sz.height()/2,
3082 sz.width(), sz.height());
3083 right = floatRect.left() - 1;
3085 if (sr == SE_DockWidgetFloatButton) {
3091 if (
const QDockWidget *dw = qobject_cast<
const QDockWidget*>(widget)) {
3093 if (dw->isFloating())
3094 icon = dw->windowIcon();
3096 && icon.cacheKey() != QApplication::windowIcon().cacheKey()) {
3097 QSize sz = icon.actualSize(QSize(r.height(), r.height()));
3098 if (verticalTitleBar)
3099 sz = sz.transposed();
3100 iconRect = QRect(left, rect.center().y() - sz.height()/2,
3101 sz.width(), sz.height());
3102 left = iconRect.right() + margin;
3105 if (sr == SE_DockWidgetIcon) {
3110 QRect textRect = QRect(left, rect.top(),
3111 right - left, rect.height());
3112 if (sr == SE_DockWidgetTitleBarText) {
3119 if (verticalTitleBar) {
3120 r = QRect(rect.left() + r.top() - rect.top(),
3121 rect.top() + rect.right() - r.right(),
3122 r.height(), r.width());
3124 r = visualRect(opt->direction, rect, r);
3129#if QT_CONFIG(itemviews)
3130 case SE_ItemViewItemCheckIndicator:
3131 if (!qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
3132 r = subElementRect(SE_CheckBoxIndicator, opt, widget);
3136 case SE_ItemViewItemDecoration:
3137 case SE_ItemViewItemText:
3138 case SE_ItemViewItemFocusRect:
3139 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
3140 if (!d->isViewItemCached(*vopt)) {
3141 d->viewItemLayout(vopt, &d->checkRect, &d->decorationRect, &d->displayRect,
false);
3142 if (d->cachedOption) {
3143 delete d->cachedOption;
3144 d->cachedOption =
nullptr;
3146 d->cachedOption =
new QStyleOptionViewItem(*vopt);
3148 if (sr == SE_ItemViewItemCheckIndicator)
3150 else if (sr == SE_ItemViewItemDecoration)
3151 r = d->decorationRect;
3152 else if (sr == SE_ItemViewItemText || sr == SE_ItemViewItemFocusRect)
3157#if QT_CONFIG(toolbar)
3158 case SE_ToolBarHandle:
3159 if (
const QStyleOptionToolBar *tbopt = qstyleoption_cast<
const QStyleOptionToolBar *>(opt)) {
3160 if (tbopt->features & QStyleOptionToolBar::Movable) {
3163 const QToolBar *tb = qobject_cast<
const QToolBar*>(widget);
3164 const QMargins margins = tb && tb->layout() ? tb->layout()->contentsMargins() : QMargins(2, 2, 2, 2);
3165 const int handleExtent = proxy()->pixelMetric(QStyle::PM_ToolBarHandleExtent, opt, tb);
3166 if (tbopt->state & QStyle::State_Horizontal) {
3167 r = QRect(margins.left(), margins.top(),
3169 tbopt->rect.height() - (margins.top() + margins.bottom()));
3170 r = QStyle::visualRect(tbopt->direction, tbopt->rect, r);
3172 r = QRect(margins.left(), margins.top(),
3173 tbopt->rect.width() - (margins.left() + margins.right()),
3184#if !QT_CONFIG(tabwidget) && !QT_CONFIG(itemviews)
3242void QCommonStyle::drawComplexControl(ComplexControl cc,
const QStyleOptionComplex *opt,
3243 QPainter *p,
const QWidget *widget)
const
3246#if QT_CONFIG(slider)
3248 if (
const QStyleOptionSlider *slider = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
3249 if (slider->subControls == SC_SliderTickmarks) {
3250 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider, widget);
3251 int ticks = slider->tickPosition;
3252 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
3253 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
3254 int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget);
3255 int interval = slider->tickInterval;
3256 if (interval <= 0) {
3257 interval = slider->singleStep;
3258 if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
3260 - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3262 interval = slider->pageStep;
3266 int fudge = len / 2;
3269 QPainterStateGuard psg(p);
3270 p->translate(slider->rect.x(), slider->rect.y());
3271 p->setPen(slider->palette.windowText().color());
3272 int v = slider->minimum;
3273 while (v <= slider->maximum + 1) {
3274 if (v == slider->maximum + 1 && interval == 1)
3276 const int v_ = qMin(v, slider->maximum);
3277 pos = QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3278 v_, available) + fudge;
3279 if (slider->orientation == Qt::Horizontal) {
3280 if (ticks & QSlider::TicksAbove)
3281 p->drawLine(pos, 0, pos, tickOffset - 2);
3282 if (ticks & QSlider::TicksBelow)
3283 p->drawLine(pos, tickOffset + thickness + 1, pos,
3284 slider->rect.height()-1);
3286 if (ticks & QSlider::TicksAbove)
3287 p->drawLine(0, pos, tickOffset - 2, pos);
3288 if (ticks & QSlider::TicksBelow)
3289 p->drawLine(tickOffset + thickness + 1, pos,
3290 slider->rect.width()-1, pos);
3293 int nextInterval = v + interval;
3294 if (nextInterval < v)
3302#if QT_CONFIG(scrollbar)
3304 if (
const QStyleOptionSlider *scrollbar = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
3306 QStyleOptionSlider newScrollbar = *scrollbar;
3307 State saveFlags = scrollbar->state;
3309 if (scrollbar->subControls & SC_ScrollBarSubLine) {
3310 newScrollbar.state = saveFlags;
3311 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarSubLine, widget);
3312 if (newScrollbar.rect.isValid()) {
3313 if (!(scrollbar->activeSubControls & SC_ScrollBarSubLine))
3314 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3315 proxy()->drawControl(CE_ScrollBarSubLine, &newScrollbar, p, widget);
3318 if (scrollbar->subControls & SC_ScrollBarAddLine) {
3319 newScrollbar.rect = scrollbar->rect;
3320 newScrollbar.state = saveFlags;
3321 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarAddLine, widget);
3322 if (newScrollbar.rect.isValid()) {
3323 if (!(scrollbar->activeSubControls & SC_ScrollBarAddLine))
3324 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3325 proxy()->drawControl(CE_ScrollBarAddLine, &newScrollbar, p, widget);
3328 if (scrollbar->subControls & SC_ScrollBarSubPage) {
3329 newScrollbar.rect = scrollbar->rect;
3330 newScrollbar.state = saveFlags;
3331 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarSubPage, widget);
3332 if (newScrollbar.rect.isValid()) {
3333 if (!(scrollbar->activeSubControls & SC_ScrollBarSubPage))
3334 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3335 proxy()->drawControl(CE_ScrollBarSubPage, &newScrollbar, p, widget);
3338 if (scrollbar->subControls & SC_ScrollBarAddPage) {
3339 newScrollbar.rect = scrollbar->rect;
3340 newScrollbar.state = saveFlags;
3341 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarAddPage, widget);
3342 if (newScrollbar.rect.isValid()) {
3343 if (!(scrollbar->activeSubControls & SC_ScrollBarAddPage))
3344 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3345 proxy()->drawControl(CE_ScrollBarAddPage, &newScrollbar, p, widget);
3348 if (scrollbar->subControls & SC_ScrollBarFirst) {
3349 newScrollbar.rect = scrollbar->rect;
3350 newScrollbar.state = saveFlags;
3351 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarFirst, widget);
3352 if (newScrollbar.rect.isValid()) {
3353 if (!(scrollbar->activeSubControls & SC_ScrollBarFirst))
3354 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3355 proxy()->drawControl(CE_ScrollBarFirst, &newScrollbar, p, widget);
3358 if (scrollbar->subControls & SC_ScrollBarLast) {
3359 newScrollbar.rect = scrollbar->rect;
3360 newScrollbar.state = saveFlags;
3361 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarLast, widget);
3362 if (newScrollbar.rect.isValid()) {
3363 if (!(scrollbar->activeSubControls & SC_ScrollBarLast))
3364 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3365 proxy()->drawControl(CE_ScrollBarLast, &newScrollbar, p, widget);
3368 if (scrollbar->subControls & SC_ScrollBarSlider) {
3369 newScrollbar.rect = scrollbar->rect;
3370 newScrollbar.state = saveFlags;
3371 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarSlider, widget);
3372 if (newScrollbar.rect.isValid()) {
3373 if (!(scrollbar->activeSubControls & SC_ScrollBarSlider))
3374 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3375 proxy()->drawControl(CE_ScrollBarSlider, &newScrollbar, p, widget);
3377 if (scrollbar->state & State_HasFocus) {
3378 QStyleOptionFocusRect fropt;
3379 fropt.QStyleOption::operator=(newScrollbar);
3380 fropt.rect.setRect(newScrollbar.rect.x() + 2, newScrollbar.rect.y() + 2,
3381 newScrollbar.rect.width() - 5,
3382 newScrollbar.rect.height() - 5);
3383 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
3390#if QT_CONFIG(spinbox)
3392 if (
const QStyleOptionSpinBox *sb = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
3393 QStyleOptionSpinBox copy = *sb;
3394 PrimitiveElement pe;
3396 if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
3397 QRect r = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxFrame, widget);
3398 qDrawWinPanel(p, r, sb->palette,
true);
3401 if (sb->subControls & SC_SpinBoxUp) {
3402 copy.subControls = SC_SpinBoxUp;
3403 QPalette pal2 = sb->palette;
3404 if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled)) {
3405 pal2.setCurrentColorGroup(QPalette::Disabled);
3406 copy.state &= ~State_Enabled;
3409 copy.palette = pal2;
3411 if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken)) {
3412 copy.state |= State_On;
3413 copy.state |= State_Sunken;
3415 copy.state |= State_Raised;
3416 copy.state &= ~State_Sunken;
3418 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
3419 : PE_IndicatorSpinUp);
3421 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget);
3422 proxy()->drawPrimitive(PE_PanelButtonBevel, ©, p, widget);
3423 copy.rect.adjust(3, 0, -4, 0);
3424 proxy()->drawPrimitive(pe, ©, p, widget);
3427 if (sb->subControls & SC_SpinBoxDown) {
3428 copy.subControls = SC_SpinBoxDown;
3429 copy.state = sb->state;
3430 QPalette pal2 = sb->palette;
3431 if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled)) {
3432 pal2.setCurrentColorGroup(QPalette::Disabled);
3433 copy.state &= ~State_Enabled;
3435 copy.palette = pal2;
3437 if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken)) {
3438 copy.state |= State_On;
3439 copy.state |= State_Sunken;
3441 copy.state |= State_Raised;
3442 copy.state &= ~State_Sunken;
3444 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
3445 : PE_IndicatorSpinDown);
3447 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget);
3448 proxy()->drawPrimitive(PE_PanelButtonBevel, ©, p, widget);
3449 copy.rect.adjust(3, 0, -4, 0);
3450 proxy()->drawPrimitive(pe, ©, p, widget);
3455#if QT_CONFIG(toolbutton)
3457 if (
const QStyleOptionToolButton *toolbutton
3458 = qstyleoption_cast<
const QStyleOptionToolButton *>(opt)) {
3459 QRect button, menuarea;
3460 button = proxy()->subControlRect(cc, toolbutton, SC_ToolButton, widget);
3461 menuarea = proxy()->subControlRect(cc, toolbutton, SC_ToolButtonMenu, widget);
3463 State bflags = toolbutton->state & ~State_Sunken;
3465 if (bflags & State_AutoRaise) {
3466 if (!(bflags & State_MouseOver) || !(bflags & State_Enabled)) {
3467 bflags &= ~State_Raised;
3470 State mflags = bflags;
3471 if (toolbutton->state & State_Sunken) {
3472 if (toolbutton->activeSubControls & SC_ToolButton)
3473 bflags |= State_Sunken;
3474 mflags |= State_Sunken;
3477 QStyleOption tool = *toolbutton;
3478 if (toolbutton->subControls & SC_ToolButton) {
3479 if (bflags & (State_Sunken | State_On | State_Raised)) {
3481 tool.state = bflags;
3482 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3486 if (toolbutton->state & State_HasFocus) {
3487 QStyleOptionFocusRect fr;
3488 fr.QStyleOption::operator=(*toolbutton);
3489 fr.rect.adjust(3, 3, -3, -3);
3490 if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup)
3491 fr.rect.adjust(0, 0, -proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator,
3492 toolbutton, widget), 0);
3493 proxy()->drawPrimitive(PE_FrameFocusRect, &fr, p, widget);
3495 QStyleOptionToolButton label = *toolbutton;
3496 label.state = bflags;
3497 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget);
3498 label.rect = button.adjusted(fw, fw, -fw, -fw);
3499 proxy()->drawControl(CE_ToolButtonLabel, &label, p, widget);
3501 if (toolbutton->subControls & SC_ToolButtonMenu) {
3502 tool.rect = menuarea;
3503 tool.state = mflags;
3504 if (mflags & (State_Sunken | State_On | State_Raised))
3505 proxy()->drawPrimitive(PE_IndicatorButtonDropDown, &tool, p, widget);
3506 proxy()->drawPrimitive(PE_IndicatorArrowDown, &tool, p, widget);
3507 }
else if (toolbutton->features & QStyleOptionToolButton::HasMenu) {
3508 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, toolbutton, widget);
3509 QRect ir = toolbutton->rect;
3510 QStyleOptionToolButton newBtn = *toolbutton;
3511 newBtn.rect = QRect(ir.right() + 5 - mbi, ir.y() + ir.height() - mbi + 4, mbi - 6, mbi - 6);
3512 newBtn.rect = visualRect(toolbutton->direction, button, newBtn.rect);
3513 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, p, widget);
3519 if (
const QStyleOptionTitleBar *tb = qstyleoption_cast<
const QStyleOptionTitleBar *>(opt)) {
3521 if (opt->subControls & SC_TitleBarLabel) {
3522 QColor left = tb->palette.highlight().color();
3523 QColor right = tb->palette.base().color();
3525 QBrush fillBrush(left);
3526 if (left != right) {
3527 QPoint p1(tb->rect.x(), tb->rect.top() + tb->rect.height()/2);
3528 QPoint p2(tb->rect.right(), tb->rect.top() + tb->rect.height()/2);
3529 QLinearGradient lg(p1, p2);
3530 lg.setColorAt(0, left);
3531 lg.setColorAt(1, right);
3535 p->fillRect(opt->rect, fillBrush);
3537 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarLabel, widget);
3539 p->setPen(tb->palette.highlightedText().color());
3540 p->drawText(ir.x() + 2, ir.y(), ir.width() - 2, ir.height(),
3541 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text);
3547 QStyleOption tool = *tb;
3548 if (tb->subControls & SC_TitleBarCloseButton && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3549 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarCloseButton, widget);
3550 down = tb->activeSubControls & SC_TitleBarCloseButton && (opt->state & State_Sunken);
3551 if ((tb->titleBarFlags & Qt::WindowType_Mask) == Qt::Tool
3552#if QT_CONFIG(dockwidget)
3553 || qobject_cast<
const QDockWidget *>(widget)
3556 pm = proxy()->standardIcon(SP_DockWidgetCloseButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3558 pm = proxy()->standardIcon(SP_TitleBarCloseButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3560 tool.state = down ? State_Sunken : State_Raised;
3561 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3563 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3564 : QPainterStateGuard::InitialState::NoSave);
3566 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3567 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3568 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3571 if (tb->subControls & SC_TitleBarMaxButton
3572 && tb->titleBarFlags & Qt::WindowMaximizeButtonHint
3573 && !(tb->titleBarState & Qt::WindowMaximized)) {
3574 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarMaxButton, widget);
3576 down = tb->activeSubControls & SC_TitleBarMaxButton && (opt->state & State_Sunken);
3577 pm = proxy()->standardIcon(SP_TitleBarMaxButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3579 tool.state = down ? State_Sunken : State_Raised;
3580 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3582 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3583 : QPainterStateGuard::InitialState::NoSave);
3585 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3586 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3587 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3590 if (tb->subControls & SC_TitleBarMinButton
3591 && tb->titleBarFlags & Qt::WindowMinimizeButtonHint
3592 && !(tb->titleBarState & Qt::WindowMinimized)) {
3593 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarMinButton, widget);
3594 down = tb->activeSubControls & SC_TitleBarMinButton && (opt->state & State_Sunken);
3595 pm = proxy()->standardIcon(SP_TitleBarMinButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3597 tool.state = down ? State_Sunken : State_Raised;
3598 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3600 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3601 : QPainterStateGuard::InitialState::NoSave);
3603 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3604 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3605 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3608 bool drawNormalButton = (tb->subControls & SC_TitleBarNormalButton)
3609 && (((tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
3610 && (tb->titleBarState & Qt::WindowMinimized))
3611 || ((tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
3612 && (tb->titleBarState & Qt::WindowMaximized)));
3614 if (drawNormalButton) {
3615 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarNormalButton, widget);
3616 down = tb->activeSubControls & SC_TitleBarNormalButton && (opt->state & State_Sunken);
3617 pm = proxy()->standardIcon(SP_TitleBarNormalButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3619 tool.state = down ? State_Sunken : State_Raised;
3620 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3622 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3623 : QPainterStateGuard::InitialState::NoSave);
3625 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3626 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3627 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3630 if (tb->subControls & SC_TitleBarShadeButton
3631 && tb->titleBarFlags & Qt::WindowShadeButtonHint
3632 && !(tb->titleBarState & Qt::WindowMinimized)) {
3633 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarShadeButton, widget);
3634 down = (tb->activeSubControls & SC_TitleBarShadeButton && (opt->state & State_Sunken));
3635 pm = proxy()->standardIcon(SP_TitleBarShadeButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3637 tool.state = down ? State_Sunken : State_Raised;
3638 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3640 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3641 : QPainterStateGuard::InitialState::NoSave);
3643 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3644 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3645 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3648 if (tb->subControls & SC_TitleBarUnshadeButton
3649 && tb->titleBarFlags & Qt::WindowShadeButtonHint
3650 && tb->titleBarState & Qt::WindowMinimized) {
3651 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarUnshadeButton, widget);
3653 down = tb->activeSubControls & SC_TitleBarUnshadeButton && (opt->state & State_Sunken);
3654 pm = proxy()->standardIcon(SP_TitleBarUnshadeButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3656 tool.state = down ? State_Sunken : State_Raised;
3657 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3659 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3660 : QPainterStateGuard::InitialState::NoSave);
3662 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3663 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3664 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3666 if (tb->subControls & SC_TitleBarContextHelpButton
3667 && tb->titleBarFlags & Qt::WindowContextHelpButtonHint) {
3668 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarContextHelpButton, widget);
3670 down = tb->activeSubControls & SC_TitleBarContextHelpButton && (opt->state & State_Sunken);
3671 pm = proxy()->standardIcon(SP_TitleBarContextHelpButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3673 tool.state = down ? State_Sunken : State_Raised;
3674 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3676 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3677 : QPainterStateGuard::InitialState::NoSave);
3679 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3680 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3681 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3683 if (tb->subControls & SC_TitleBarSysMenu && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3684 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarSysMenu, widget);
3685 if (!tb->icon.isNull()) {
3686 tb->icon.paint(p, ir);
3688 int iconSize = proxy()->pixelMetric(PM_SmallIconSize, tb, widget);
3689 pm = proxy()->standardIcon(SP_TitleBarMenuButton, &tool, widget).pixmap(QSize(iconSize, iconSize), QStyleHelper::getDpr(p));
3691 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3698 if (
const QStyleOptionSlider *dial = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
3700 QPainterStateGuard psg(p);
3703 if (p->paintEngine()->hasFeature(QPaintEngine::Antialiasing))
3704 p->setRenderHint(QPainter::Antialiasing);
3706 int width = dial->rect.width();
3707 int height = dial->rect.height();
3708 qreal r = qMin(width, height) / 2;
3710 qreal dx = dial->rect.x() + d_ + (width - 2 * r) / 2 + 1;
3711 qreal dy = dial->rect.y() + d_ + (height - 2 * r) / 2 + 1;
3712 QRect br = QRect(
int(dx),
int(dy),
int(r * 2 - 2 * d_ - 2),
int(r * 2 - 2 * d_ - 2));
3714 QPalette pal = opt->palette;
3716 if (dial->subControls & QStyle::SC_DialTickmarks) {
3717 p->setPen(pal.windowText().color());
3718 p->drawLines(QStyleHelper::calcLines(dial));
3721 if (dial->state & State_Enabled) {
3722 p->setBrush(pal.brush(QPalette::ColorRole(proxy()->styleHint(SH_Dial_BackgroundRole,
3724 p->setPen(Qt::NoPen);
3726 p->setBrush(Qt::NoBrush);
3728 p->setPen(pal.dark().color());
3729 p->drawArc(br, 60 * 16, 180 * 16);
3730 p->setPen(pal.light().color());
3731 p->drawArc(br, 240 * 16, 180 * 16);
3734 const StaticPolygonF<3> arrow = calcArrow(dial, a);
3736 p->setPen(Qt::NoPen);
3737 p->setBrush(pal.button());
3738 p->drawPolygon(arrow.cbegin(), arrow.size());
3740 a = QStyleHelper::angle(QPointF(width / 2, height / 2), arrow[0]);
3741 p->setBrush(Qt::NoBrush);
3743 if (a <= 0 || a > 200) {
3744 p->setPen(pal.light().color());
3745 p->drawLine(arrow[2], arrow[0]);
3746 p->drawLine(arrow[1], arrow[2]);
3747 p->setPen(pal.dark().color());
3748 p->drawLine(arrow[0], arrow[1]);
3749 }
else if (a > 0 && a < 45) {
3750 p->setPen(pal.light().color());
3751 p->drawLine(arrow[2], arrow[0]);
3752 p->setPen(pal.dark().color());
3753 p->drawLine(arrow[1], arrow[2]);
3754 p->drawLine(arrow[0], arrow[1]);
3755 }
else if (a >= 45 && a < 135) {
3756 p->setPen(pal.dark().color());
3757 p->drawLine(arrow[2], arrow[0]);
3758 p->drawLine(arrow[1], arrow[2]);
3759 p->setPen(pal.light().color());
3760 p->drawLine(arrow[0], arrow[1]);
3761 }
else if (a >= 135 && a < 200) {
3762 p->setPen(pal.dark().color());
3763 p->drawLine(arrow[2], arrow[0]);
3764 p->setPen(pal.light().color());
3765 p->drawLine(arrow[0], arrow[1]);
3766 p->drawLine(arrow[1], arrow[2]);
3770 QStyleOptionFocusRect fropt;
3771 fropt.rect = dial->rect;
3772 fropt.state = dial->state;
3773 fropt.palette = dial->palette;
3774 if (fropt.state & QStyle::State_HasFocus) {
3775 br.adjust(0, 0, 2, 2);
3776 if (dial->subControls & SC_DialTickmarks) {
3777 int r = qMin(width, height) / 2;
3778 br.translate(-r / 6, - r / 6);
3779 br.setWidth(br.width() + r / 3);
3780 br.setHeight(br.height() + r / 3);
3782 fropt.rect = br.adjusted(-2, -2, 2, 2);
3783 proxy()->drawPrimitive(QStyle::PE_FrameFocusRect, &fropt, p, widget);
3788#if QT_CONFIG(groupbox)
3790 if (
const QStyleOptionGroupBox *groupBox = qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
3792 QRect textRect = proxy()->subControlRect(CC_GroupBox, opt, SC_GroupBoxLabel, widget);
3793 QRect checkBoxRect = proxy()->subControlRect(CC_GroupBox, opt, SC_GroupBoxCheckBox, widget);
3794 if (groupBox->subControls & QStyle::SC_GroupBoxFrame) {
3795 QStyleOptionFrame frame;
3796 frame.QStyleOption::operator=(*groupBox);
3797 frame.features = groupBox->features;
3798 frame.lineWidth = groupBox->lineWidth;
3799 frame.midLineWidth = groupBox->midLineWidth;
3800 frame.rect = proxy()->subControlRect(CC_GroupBox, opt, SC_GroupBoxFrame, widget);
3801 QPainterStateGuard psg(p);
3802 QRegion region(groupBox->rect);
3803 if (!groupBox->text.isEmpty()) {
3804 bool ltr = groupBox->direction == Qt::LeftToRight;
3806 if (groupBox->subControls & QStyle::SC_GroupBoxCheckBox) {
3807 finalRect = checkBoxRect.united(textRect);
3808 finalRect.adjust(ltr ? -4 : 0, 0, ltr ? 0 : 4, 0);
3810 finalRect = textRect;
3812 region -= finalRect;
3814 p->setClipRegion(region);
3815 proxy()->drawPrimitive(PE_FrameGroupBox, &frame, p, widget);
3819 if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
3820 QColor textColor = groupBox->textColor;
3821 if (textColor.isValid())
3822 p->setPen(textColor);
3823 int alignment =
int(groupBox->textAlignment);
3824 if (!proxy()->styleHint(QStyle::SH_UnderlineShortcut, opt, widget))
3825 alignment |= Qt::TextHideMnemonic;
3827 proxy()->drawItemText(p, textRect, Qt::TextShowMnemonic | Qt::AlignHCenter | alignment,
3828 groupBox->palette, groupBox->state & State_Enabled, groupBox->text,
3829 textColor.isValid() ? QPalette::NoRole : QPalette::WindowText);
3831 if (groupBox->state & State_HasFocus) {
3832 QStyleOptionFocusRect fropt;
3833 fropt.QStyleOption::operator=(*groupBox);
3834 fropt.rect = textRect;
3835 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
3840 if (groupBox->subControls & SC_GroupBoxCheckBox) {
3841 QStyleOptionButton box;
3842 box.QStyleOption::operator=(*groupBox);
3843 box.rect = checkBoxRect;
3844 proxy()->drawPrimitive(PE_IndicatorCheckBox, &box, p, widget);
3849#if QT_CONFIG(mdiarea)
3850 case CC_MdiControls:
3852 QStyleOptionButton btnOpt;
3853 btnOpt.QStyleOption::operator=(*opt);
3854 btnOpt.state &= ~State_MouseOver;
3857 const int buttonIconMetric = proxy()->pixelMetric(PM_TitleBarButtonIconSize, &btnOpt, widget);
3858 const QSize buttonIconSize(buttonIconMetric, buttonIconMetric);
3859 if (opt->subControls & QStyle::SC_MdiCloseButton) {
3860 if (opt->activeSubControls & QStyle::SC_MdiCloseButton && (opt->state & State_Sunken)) {
3861 btnOpt.state |= State_Sunken;
3862 btnOpt.state &= ~State_Raised;
3863 bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget);
3864 bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget);
3866 btnOpt.state |= State_Raised;
3867 btnOpt.state &= ~State_Sunken;
3871 btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiCloseButton, widget);
3872 proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p, widget);
3873 QPixmap pm = proxy()->standardIcon(SP_TitleBarCloseButton).pixmap(buttonIconSize, QStyleHelper::getDpr(p));
3874 proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm);
3876 if (opt->subControls & QStyle::SC_MdiNormalButton) {
3877 if (opt->activeSubControls & QStyle::SC_MdiNormalButton && (opt->state & State_Sunken)) {
3878 btnOpt.state |= State_Sunken;
3879 btnOpt.state &= ~State_Raised;
3880 bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget);
3881 bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget);
3883 btnOpt.state |= State_Raised;
3884 btnOpt.state &= ~State_Sunken;
3888 btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiNormalButton, widget);
3889 proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p, widget);
3890 QPixmap pm = proxy()->standardIcon(SP_TitleBarNormalButton).pixmap(buttonIconSize, QStyleHelper::getDpr(p));
3891 proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm);
3893 if (opt->subControls & QStyle::SC_MdiMinButton) {
3894 if (opt->activeSubControls & QStyle::SC_MdiMinButton && (opt->state & State_Sunken)) {
3895 btnOpt.state |= State_Sunken;
3896 btnOpt.state &= ~State_Raised;
3897 bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget);
3898 bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget);
3900 btnOpt.state |= State_Raised;
3901 btnOpt.state &= ~State_Sunken;
3905 btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiMinButton, widget);
3906 proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p, widget);
3907 QPixmap pm = proxy()->standardIcon(SP_TitleBarMinButton).pixmap(buttonIconSize, QStyleHelper::getDpr(p));
3908 proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm);
3914 qCWarning(lcCommonStyle,
"QCommonStyle::drawComplexControl: Control %d not handled", cc);
4058QRect QCommonStyle::subControlRect(ComplexControl cc,
const QStyleOptionComplex *opt,
4059 SubControl sc,
const QWidget *widget)
const
4063#if QT_CONFIG(slider)
4065 if (
const QStyleOptionSlider *slider = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
4066 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider, widget);
4067 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
4070 case SC_SliderHandle: {
4072 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
4073 bool horizontal = slider->orientation == Qt::Horizontal;
4074 sliderPos = sliderPositionFromValue(slider->minimum, slider->maximum,
4075 slider->sliderPosition,
4076 (horizontal ? slider->rect.width()
4077 : slider->rect.height()) - len,
4078 slider->upsideDown);
4080 ret.setRect(slider->rect.x() + sliderPos, slider->rect.y() + tickOffset, len, thickness);
4082 ret.setRect(slider->rect.x() + tickOffset, slider->rect.y() + sliderPos, thickness, len);
4084 case SC_SliderGroove:
4085 if (slider->orientation == Qt::Horizontal)
4086 ret.setRect(slider->rect.x(), slider->rect.y() + tickOffset,
4087 slider->rect.width(), thickness);
4089 ret.setRect(slider->rect.x() + tickOffset, slider->rect.y(),
4090 thickness, slider->rect.height());
4095 ret = visualRect(slider->direction, slider->rect, ret);
4099#if QT_CONFIG(scrollbar)
4101 if (
const QStyleOptionSlider *scrollbar = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
4102 const QRect scrollBarRect = scrollbar->rect;
4104 if (!proxy()->styleHint(SH_ScrollBar_Transient, scrollbar, widget))
4105 sbextent = proxy()->pixelMetric(PM_ScrollBarExtent, scrollbar, widget);
4106 int maxlen = ((scrollbar->orientation == Qt::Horizontal) ?
4107 scrollBarRect.width() : scrollBarRect.height()) - (sbextent * 2);
4111 if (scrollbar->maximum != scrollbar->minimum) {
4112 uint range = scrollbar->maximum - scrollbar->minimum;
4113 sliderlen = (qint64(scrollbar->pageStep) * maxlen) / (range + scrollbar->pageStep);
4115 int slidermin = proxy()->pixelMetric(PM_ScrollBarSliderMin, scrollbar, widget);
4116 if (sliderlen < slidermin || range > INT_MAX / 2)
4117 sliderlen = slidermin;
4118 if (sliderlen > maxlen)
4124 int sliderstart = sbextent + sliderPositionFromValue(scrollbar->minimum,
4126 scrollbar->sliderPosition,
4128 scrollbar->upsideDown);
4131 case SC_ScrollBarSubLine:
4132 if (scrollbar->orientation == Qt::Horizontal) {
4133 int buttonWidth = qMin(scrollBarRect.width() / 2, sbextent);
4134 ret.setRect(0, 0, buttonWidth, scrollBarRect.height());
4136 int buttonHeight = qMin(scrollBarRect.height() / 2, sbextent);
4137 ret.setRect(0, 0, scrollBarRect.width(), buttonHeight);
4140 case SC_ScrollBarAddLine:
4141 if (scrollbar->orientation == Qt::Horizontal) {
4142 int buttonWidth = qMin(scrollBarRect.width()/2, sbextent);
4143 ret.setRect(scrollBarRect.width() - buttonWidth, 0, buttonWidth, scrollBarRect.height());
4145 int buttonHeight = qMin(scrollBarRect.height()/2, sbextent);
4146 ret.setRect(0, scrollBarRect.height() - buttonHeight, scrollBarRect.width(), buttonHeight);
4149 case SC_ScrollBarSubPage:
4150 if (scrollbar->orientation == Qt::Horizontal)
4151 ret.setRect(sbextent, 0, sliderstart - sbextent, scrollBarRect.height());
4153 ret.setRect(0, sbextent, scrollBarRect.width(), sliderstart - sbextent);
4155 case SC_ScrollBarAddPage:
4156 if (scrollbar->orientation == Qt::Horizontal)
4157 ret.setRect(sliderstart + sliderlen, 0,
4158 maxlen - sliderstart - sliderlen + sbextent, scrollBarRect.height());
4160 ret.setRect(0, sliderstart + sliderlen, scrollBarRect.width(),
4161 maxlen - sliderstart - sliderlen + sbextent);
4163 case SC_ScrollBarGroove:
4164 if (scrollbar->orientation == Qt::Horizontal)
4165 ret.setRect(sbextent, 0, scrollBarRect.width() - sbextent * 2,
4166 scrollBarRect.height());
4168 ret.setRect(0, sbextent, scrollBarRect.width(),
4169 scrollBarRect.height() - sbextent * 2);
4171 case SC_ScrollBarSlider:
4172 if (scrollbar->orientation == Qt::Horizontal)
4173 ret.setRect(sliderstart, 0, sliderlen, scrollBarRect.height());
4175 ret.setRect(0, sliderstart, scrollBarRect.width(), sliderlen);
4180 ret = visualRect(scrollbar->direction, scrollBarRect, ret);
4184#if QT_CONFIG(spinbox)
4186 if (
const QStyleOptionSpinBox *spinbox = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
4188 int fw = spinbox->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget) : 0;
4189 bs.setHeight(qMax(8, spinbox->rect.height()/2 - fw));
4191 bs.setWidth(qMax(16, qMin(bs.height() * 8 / 5, spinbox->rect.width() / 4)));
4192 int y = fw + spinbox->rect.y();
4194 x = spinbox->rect.x() + spinbox->rect.width() - fw - bs.width();
4199 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
4201 ret = QRect(x, y, bs.width(), bs.height());
4203 case SC_SpinBoxDown:
4204 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
4207 ret = QRect(x, y + bs.height(), bs.width(), bs.height());
4209 case SC_SpinBoxEditField:
4210 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons) {
4211 ret = QRect(lx, fw, spinbox->rect.width() - 2*fw, spinbox->rect.height() - 2*fw);
4213 ret = QRect(lx, fw, rx, spinbox->rect.height() - 2*fw);
4216 case SC_SpinBoxFrame:
4217 ret = spinbox->rect;
4222 ret = visualRect(spinbox->direction, spinbox->rect, ret);
4226#if QT_CONFIG(toolbutton)
4228 if (
const QStyleOptionToolButton *tb = qstyleoption_cast<
const QStyleOptionToolButton *>(opt)) {
4229 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, tb, widget);
4234 & (QStyleOptionToolButton::MenuButtonPopup | QStyleOptionToolButton::PopupDelay))
4235 == QStyleOptionToolButton::MenuButtonPopup)
4236 ret.adjust(0, 0, -mbi, 0);
4238 case SC_ToolButtonMenu:
4240 & (QStyleOptionToolButton::MenuButtonPopup | QStyleOptionToolButton::PopupDelay))
4241 == QStyleOptionToolButton::MenuButtonPopup)
4242 ret.adjust(ret.width() - mbi, 0, 0, 0);
4247 ret = visualRect(tb->direction, tb->rect, ret);
4251#if QT_CONFIG(combobox)
4253 if (
const QStyleOptionComboBox *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
4254 const qreal dpi = QStyleHelper::dpi(opt);
4255 const int x = cb->rect.x(), y = cb->rect.y(), wi = cb->rect.width(), he = cb->rect.height();
4256 const int margin = cb->frame ? qRound(QStyleHelper::dpiScaled(3, dpi)) : 0;
4257 const int bmarg = cb->frame ? qRound(QStyleHelper::dpiScaled(2, dpi)) : 0;
4258 const int xpos = x + wi - bmarg - qRound(QStyleHelper::dpiScaled(16, dpi));
4262 case SC_ComboBoxFrame:
4265 case SC_ComboBoxArrow:
4266 ret.setRect(xpos, y + bmarg, qRound(QStyleHelper::dpiScaled(16, opt)), he - 2*bmarg);
4268 case SC_ComboBoxEditField:
4269 ret.setRect(x + margin, y + margin, wi - 2 * margin - qRound(QStyleHelper::dpiScaled(16, dpi)), he - 2 * margin);
4271 case SC_ComboBoxListBoxPopup:
4277 ret = visualRect(cb->direction, cb->rect, ret);
4282 if (
const QStyleOptionTitleBar *tb = qstyleoption_cast<
const QStyleOptionTitleBar *>(opt)) {
4283 const int controlMargin = 2;
4284 const int controlHeight = tb->rect.height() - controlMargin *2;
4285 const int delta = controlHeight + controlMargin;
4288 bool isMinimized = tb->titleBarState & Qt::WindowMinimized;
4289 bool isMaximized = tb->titleBarState & Qt::WindowMaximized;
4292 case SC_TitleBarLabel:
4293 if (tb->titleBarFlags & (Qt::WindowTitleHint | Qt::WindowSystemMenuHint)) {
4295 if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
4296 ret.adjust(delta, 0, -delta, 0);
4297 if (tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
4298 ret.adjust(0, 0, -delta, 0);
4299 if (tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
4300 ret.adjust(0, 0, -delta, 0);
4301 if (tb->titleBarFlags & Qt::WindowShadeButtonHint)
4302 ret.adjust(0, 0, -delta, 0);
4303 if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
4304 ret.adjust(0, 0, -delta, 0);
4307 case SC_TitleBarContextHelpButton:
4308 if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
4311 case SC_TitleBarMinButton:
4312 if (!isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
4314 else if (sc == SC_TitleBarMinButton)
4317 case SC_TitleBarNormalButton:
4318 if (isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
4320 else if (isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
4322 else if (sc == SC_TitleBarNormalButton)
4325 case SC_TitleBarMaxButton:
4326 if (!isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
4328 else if (sc == SC_TitleBarMaxButton)
4331 case SC_TitleBarShadeButton:
4332 if (!isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
4334 else if (sc == SC_TitleBarShadeButton)
4337 case SC_TitleBarUnshadeButton:
4338 if (isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
4340 else if (sc == SC_TitleBarUnshadeButton)
4343 case SC_TitleBarCloseButton:
4344 if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
4346 else if (sc == SC_TitleBarCloseButton)
4348 ret.setRect(tb->rect.right() - offset, tb->rect.top() + controlMargin,
4349 controlHeight, controlHeight);
4351 case SC_TitleBarSysMenu:
4352 if (tb->titleBarFlags & Qt::WindowSystemMenuHint) {
4353 ret.setRect(tb->rect.left() + controlMargin, tb->rect.top() + controlMargin,
4354 controlHeight, controlHeight);
4360 ret = visualRect(tb->direction, tb->rect, ret);
4363#if QT_CONFIG(groupbox)
4365 if (
const QStyleOptionGroupBox *groupBox = qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
4367 case SC_GroupBoxFrame:
4368 case SC_GroupBoxContents: {
4371 int verticalAlignment = proxy()->styleHint(SH_GroupBox_TextLabelVerticalAlignment, groupBox, widget);
4372 bool hasCheckBox = groupBox->subControls & QStyle::SC_GroupBoxCheckBox;
4373 if (groupBox->text.size() || hasCheckBox) {
4374 int checkBoxHeight = hasCheckBox ? proxy()->pixelMetric(PM_IndicatorHeight, groupBox, widget) : 0;
4375 topHeight = qMax(groupBox->fontMetrics.height(), checkBoxHeight);
4376 if (verticalAlignment & Qt::AlignVCenter)
4377 topMargin = topHeight / 2;
4378 else if (verticalAlignment & Qt::AlignTop)
4379 topMargin = topHeight + proxy()->pixelMetric(PM_FocusFrameVMargin, groupBox, widget);
4382 QRect frameRect = groupBox->rect;
4383 frameRect.setTop(topMargin);
4385 if (sc == SC_GroupBoxFrame) {
4391 if ((groupBox->features & QStyleOptionFrame::Flat) == 0)
4392 frameWidth = proxy()->pixelMetric(PM_DefaultFrameWidth, groupBox, widget);
4393 ret = frameRect.adjusted(frameWidth, frameWidth + topHeight - topMargin,
4394 -frameWidth, -frameWidth);
4397 case SC_GroupBoxCheckBox:
4398 case SC_GroupBoxLabel: {
4399 QFontMetrics fontMetrics = groupBox->fontMetrics;
4400 int th = fontMetrics.height();
4401 int tw = fontMetrics.size(Qt::TextShowMnemonic, groupBox->text + u' ').width();
4402 int marg = (groupBox->features & QStyleOptionFrame::Flat) ? 0 : 8;
4403 ret = groupBox->rect.adjusted(marg, 0, -marg, 0);
4405 int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, opt, widget);
4406 int indicatorHeight = proxy()->pixelMetric(PM_IndicatorHeight, opt, widget);
4407 int indicatorSpace = proxy()->pixelMetric(PM_CheckBoxLabelSpacing, opt, widget) - 1;
4408 bool hasCheckBox = groupBox->subControls & QStyle::SC_GroupBoxCheckBox;
4409 int checkBoxWidth = hasCheckBox ? (indicatorWidth + indicatorSpace) : 0;
4410 int checkBoxHeight = hasCheckBox ? indicatorHeight : 0;
4412 int h = qMax(th, checkBoxHeight);
4416 QRect totalRect = alignedRect(groupBox->direction, groupBox->textAlignment,
4417 QSize(tw + checkBoxWidth, h), ret);
4421 bool ltr = groupBox->direction == Qt::LeftToRight;
4424 if (sc == SC_GroupBoxCheckBox) {
4425 left = ltr ? totalRect.left() : (totalRect.right() - indicatorWidth);
4426 int top = totalRect.top() + (h - checkBoxHeight) / 2;
4427 totalRect.setRect(left, top, indicatorWidth, indicatorHeight);
4430 left = ltr ? (totalRect.left() + checkBoxWidth - 2) : totalRect.left();
4431 int top = totalRect.top() + (h - th) / 2;
4432 totalRect.setRect(left, top, totalRect.width() - checkBoxWidth, th);
4445#if QT_CONFIG(mdiarea)
4446 case CC_MdiControls:
4448 int numSubControls = 0;
4449 if (opt->subControls & SC_MdiCloseButton)
4451 if (opt->subControls & SC_MdiMinButton)
4453 if (opt->subControls & SC_MdiNormalButton)
4455 if (numSubControls == 0)
4458 int buttonWidth = opt->rect.width() / numSubControls - 1;
4461 case SC_MdiCloseButton:
4463 if (numSubControls == 1)
4465 offset += buttonWidth + 2;
4467 case SC_MdiNormalButton:
4471 if (numSubControls == 1 || (numSubControls == 2 && !(opt->subControls & SC_MdiMinButton)))
4473 if (opt->subControls & SC_MdiNormalButton)
4474 offset += buttonWidth;
4483 if (numSubControls == 1)
4485 ret = QRect(offset, 0, buttonWidth, opt->rect.height());
4490 qCWarning(lcCommonStyle,
"QCommonStyle::subControlRect: Case %d not handled", cc);
4492#if !QT_CONFIG(slider) && !QT_CONFIG(spinbox) && !QT_CONFIG(toolbutton) && !QT_CONFIG(groupbox)
5873QIcon QCommonStylePrivate::iconFromResourceTheme(QCommonStyle::StandardPixmap standardIcon,
5874 const QStyleOption *option,
5875 const QWidget *widget)
const
5877 Q_Q(
const QCommonStyle);
5879#ifndef QT_NO_IMAGEFORMAT_PNG
5880 switch (standardIcon) {
5881 case QStyle::SP_MessageBoxInformation:
5882 addIconFiles(u"information-", pngIconSizes, icon);
5884 case QStyle::SP_MessageBoxWarning:
5885 addIconFiles(u"warning-", pngIconSizes, icon);
5887 case QStyle::SP_MessageBoxCritical:
5888 addIconFiles(u"critical-", pngIconSizes, icon);
5890 case QStyle::SP_MessageBoxQuestion:
5891 addIconFiles(u"question-", pngIconSizes, icon);
5893 case QStyle::SP_FileDialogStart:
5894 addIconFiles(u"filedialog_start-", pngIconSizes, icon);
5896 case QStyle::SP_FileDialogEnd:
5897 addIconFiles(u"filedialog_end-", pngIconSizes, icon);
5899 case QStyle::SP_TitleBarMinButton:
5900 addIconFiles(u"titlebar-min-", titleBarSizes, icon);
5902 case QStyle::SP_TitleBarMaxButton:
5903 addIconFiles(u"titlebar-max-", titleBarSizes, icon);
5905 case QStyle::SP_TitleBarShadeButton:
5906 addIconFiles(u"titlebar-shade-", titleBarSizes, icon);
5908 case QStyle::SP_TitleBarUnshadeButton:
5909 addIconFiles(u"titlebar-unshade-", titleBarSizes, icon);
5911 case QStyle::SP_TitleBarContextHelpButton:
5912 addIconFiles(u"titlebar-contexthelp-", titleBarSizes, icon);
5914 case QStyle::SP_FileDialogNewFolder:
5915 addIconFiles(u"newdirectory-", pngIconSizes, icon);
5917 case QStyle::SP_FileDialogBack:
5918 return q->proxy()->standardIcon(QStyle::SP_ArrowBack, option, widget);
5919 case QStyle::SP_FileDialogToParent:
5920 return q->proxy()->standardIcon(QStyle::SP_ArrowUp, option, widget);
5921 case QStyle::SP_FileDialogDetailedView:
5922 addIconFiles(u"viewdetailed-", pngIconSizes, icon);
5924 case QStyle::SP_FileDialogInfoView:
5925 addIconFiles(u"fileinfo-", pngIconSizes, icon);
5927 case QStyle::SP_FileDialogContentsView:
5928 addIconFiles(u"filecontents-", pngIconSizes, icon);
5930 case QStyle::SP_FileDialogListView:
5931 addIconFiles(u"viewlist-", pngIconSizes, icon);
5933 case QStyle::SP_DialogOkButton:
5934 addIconFiles(u"standardbutton-ok-", pngIconSizes, icon);
5936 case QStyle::SP_DialogCancelButton:
5937 addIconFiles(u"standardbutton-cancel-", pngIconSizes, icon);
5939 case QStyle::SP_DialogHelpButton:
5940 addIconFiles(u"standardbutton-help-", pngIconSizes, icon);
5942 case QStyle::SP_DialogOpenButton:
5943 addIconFiles(u"standardbutton-open-", pngIconSizes, icon);
5945 case QStyle::SP_DialogSaveButton:
5946 addIconFiles(u"standardbutton-save-", pngIconSizes, icon);
5948 case QStyle::SP_DialogCloseButton:
5949 addIconFiles(u"standardbutton-close-", pngIconSizes, icon);
5951 case QStyle::SP_DialogApplyButton:
5952 addIconFiles(u"standardbutton-apply-", pngIconSizes, icon);
5954 case QStyle::SP_DialogResetButton:
5955 addIconFiles(u"standardbutton-clear-", pngIconSizes, icon);
5957 case QStyle::SP_DialogDiscardButton:
5958 addIconFiles(u"standardbutton-delete-", pngIconSizes, icon);
5960 case QStyle::SP_DialogYesButton:
5961 addIconFiles(u"standardbutton-yes-", pngIconSizes, icon);
5963 case QStyle::SP_DialogNoButton:
5964 addIconFiles(u"standardbutton-no-", pngIconSizes, icon);
5966 case QStyle::SP_CommandLink:
5967 case QStyle::SP_ArrowForward:
5968 return q->proxy()->standardIcon(rtl(option) ? QStyle::SP_ArrowLeft
5969 : QStyle::SP_ArrowRight,
5971 case QStyle::SP_ArrowBack:
5972 return q->proxy()->standardIcon(rtl(option) ? QStyle::SP_ArrowRight
5973 : QStyle::SP_ArrowLeft,
5975 case QStyle::SP_ArrowLeft:
5976 addIconFiles(u"arrow-left-", pngIconSizes, icon);
5978 case QStyle::SP_ArrowRight:
5979 addIconFiles(u"arrow-right-", pngIconSizes, icon);
5981 case QStyle::SP_ArrowUp:
5982 addIconFiles(u"arrow-up-", pngIconSizes, icon);
5984 case QStyle::SP_ArrowDown:
5985 addIconFiles(u"arrow-down-", pngIconSizes, icon);
5987 case QStyle::SP_DirHomeIcon:
5988 case QStyle::SP_DirIcon:
5989 addIconFiles(u"dirclosed-", pngIconSizes, icon, QIcon::Normal, QIcon::Off);
5990 addIconFiles(u"diropen-", pngIconSizes, icon, QIcon::Normal, QIcon::On);
5992 case QStyle::SP_DirOpenIcon:
5993 addIconFiles(u"diropen-", pngIconSizes, icon);
5995 case QStyle::SP_DirClosedIcon:
5996 addIconFiles(u"dirclosed-", pngIconSizes, icon);
5998 case QStyle::SP_DirLinkIcon:
5999 addIconFiles(u"dirlink-", pngIconSizes, icon);
6001 case QStyle::SP_DriveCDIcon:
6002 addIconFiles(u"cdr-", pngIconSizes, icon);
6004 case QStyle::SP_DriveFDIcon:
6005 addIconFiles(u"floppy-", pngIconSizes, icon);
6007 case QStyle::SP_DriveHDIcon:
6008 addIconFiles(u"harddrive-", pngIconSizes, icon);
6010 case QStyle::SP_DriveDVDIcon:
6011 addIconFiles(u"dvd-", pngIconSizes, icon);
6013 case QStyle::SP_DriveNetIcon:
6014 addIconFiles(u"networkdrive-", pngIconSizes, icon);
6016 case QStyle::SP_FileIcon:
6017 addIconFiles(u"file-", pngIconSizes, icon);
6019 case QStyle::SP_FileLinkIcon:
6020 addIconFiles(u"filelink-", pngIconSizes, icon);
6022 case QStyle::SP_DesktopIcon:
6023 addIconFiles(u"desktop-", {16, 32}, icon);
6025 case QStyle::SP_TrashIcon:
6026 addIconFiles(u"trash-", pngIconSizes, icon);
6028 case QStyle::SP_ComputerIcon:
6029 addIconFiles(u"computer-", {16, 32}, icon);
6031 case QStyle::SP_BrowserReload:
6032 addIconFiles(u"refresh-", {24, 32}, icon);
6034 case QStyle::SP_BrowserStop:
6035 addIconFiles(u"stop-", {24, 32}, icon);
6037 case QStyle::SP_MediaPlay:
6038 addIconFiles(u"media-play-", pngIconSizes, icon);
6040 case QStyle::SP_MediaPause:
6041 addIconFiles(u"media-pause-", pngIconSizes, icon);
6043 case QStyle::SP_MediaStop:
6044 addIconFiles(u"media-stop-", pngIconSizes, icon);
6046 case QStyle::SP_MediaSeekForward:
6047 addIconFiles(u"media-seek-forward-", pngIconSizes, icon);
6049 case QStyle::SP_MediaSeekBackward:
6050 addIconFiles(u"media-seek-backward-", pngIconSizes, icon);
6052 case QStyle::SP_MediaSkipForward:
6053 addIconFiles(u"media-skip-forward-", pngIconSizes, icon);
6055 case QStyle::SP_MediaSkipBackward:
6056 addIconFiles(u"media-skip-backward-", pngIconSizes, icon);
6058 case QStyle::SP_MediaVolume:
6059 addIconFiles(u"media-volume-", pngIconSizes, icon);
6061 case QStyle::SP_MediaVolumeMuted:
6062 addIconFiles(u"media-volume-muted-", pngIconSizes, icon);
6064 case QStyle::SP_TitleBarCloseButton:
6065 case QStyle::SP_DockWidgetCloseButton:
6066 addIconFiles(u"closedock-", dockTitleIconSizes, icon);
6068 case QStyle::SP_TitleBarMenuButton:
6069# ifndef QT_NO_IMAGEFORMAT_XPM
6070 icon.addPixmap(titleBarMenuCachedPixmapFromXPM());
6072 icon.addFile(
":/qt-project.org/qmessagebox/images/qtlogo-64.png"_L1);
6074 case QStyle::SP_TitleBarNormalButton:
6075 addIconFiles(u"normalizedockup-", dockTitleIconSizes, icon);
6077 case QStyle::SP_ToolBarHorizontalExtensionButton:
6078 addIconFiles(rtl(option) ? u"toolbar-ext-h-rtl-"_sv : u"toolbar-ext-h-"_sv, toolBarExtHSizes, icon);
6080 case QStyle::SP_ToolBarVerticalExtensionButton:
6081 addIconFiles(u"toolbar-ext-v-", toolBarExtVSizes, icon);
6083 case QStyle::SP_TabCloseButton:
6084 addIconFiles(u"standardbutton-closetab-", pngIconSizes, icon, QIcon::Normal, QIcon::Off);
6085 addIconFiles(u"standardbutton-closetab-down-", pngIconSizes, icon, QIcon::Normal, QIcon::On);
6086 addIconFiles(u"standardbutton-closetab-hover-", pngIconSizes, icon, QIcon::Active, QIcon::Off);
6088 case QStyle::SP_LineEditClearButton:
6089 addIconFiles(u"cleartext-", pngIconSizes, icon);
6095 Q_UNUSED(standardIcon);