137void QCommonStyle::drawPrimitive(PrimitiveElement pe,
const QStyleOption *opt, QPainter *p,
138 const QWidget *widget)
const
140 Q_D(
const QCommonStyle);
142 case PE_FrameButtonBevel:
143 case PE_FrameButtonTool:
144 qDrawShadeRect(p, opt->rect, opt->palette,
145 opt->state & (State_Sunken | State_On), 1, 0);
147 case PE_PanelButtonCommand:
148 case PE_PanelButtonBevel:
149 case PE_PanelButtonTool:
150 case PE_IndicatorButtonDropDown:
151 qDrawShadePanel(p, opt->rect, opt->palette,
152 opt->state & (State_Sunken | State_On), 1,
153 &opt->palette.brush(QPalette::Button));
155 case PE_IndicatorItemViewItemCheck:
156 proxy()->drawPrimitive(PE_IndicatorCheckBox, opt, p, widget);
158 case PE_IndicatorCheckBox:
159 if (opt->state & State_NoChange) {
160 p->setPen(opt->palette.windowText().color());
161 p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));
162 p->drawRect(opt->rect);
163 p->drawLine(opt->rect.topLeft(), opt->rect.bottomRight());
165 qDrawShadePanel(p, opt->rect.x(), opt->rect.y(), opt->rect.width(), opt->rect.height(),
166 opt->palette, opt->state & (State_Sunken | State_On), 1,
167 &opt->palette.brush(QPalette::Button));
170 case PE_IndicatorRadioButton: {
171 QRect ir = opt->rect;
172 p->setPen(opt->palette.dark().color());
173 p->drawArc(opt->rect, 0, 5760);
174 if (opt->state & (State_Sunken | State_On)) {
175 ir.adjust(2, 2, -2, -2);
176 p->setBrush(opt->palette.windowText());
180 case PE_FrameFocusRect:
181 if (
const QStyleOptionFocusRect *fropt = qstyleoption_cast<
const QStyleOptionFocusRect *>(opt)) {
182 QColor bg = fropt->backgroundColor;
186 bg.getHsv(&h, &s, &v);
192 color = opt->palette.windowText().color();
194 const QRect focusRect = opt->rect.adjusted(1, 1, -1, -1);
195 qDrawPlainRect(p, focusRect, color, 1);
198 case PE_IndicatorMenuCheckMark: {
199 const int markW = opt->rect.width() > 7 ? 7 : opt->rect.width();
200 const int markH = markW;
201 int posX = opt->rect.x() + (opt->rect.width() - markW)/2 + 1;
202 int posY = opt->rect.y() + (opt->rect.height() - markH)/2;
210 for (i = 0; i < markW/2; ++i) {
211 a << QLineF(xx, yy, xx, yy + 2);
216 for (; i < markH; ++i) {
217 a << QLineF(xx, yy, xx, yy + 2);
221 if (!(opt->state & State_Enabled) && !(opt->state & State_On)) {
222 QPainterStateGuard psg(p);
224 p->setPen(opt->palette.light().color());
227 p->setPen((opt->state & State_On) ? opt->palette.highlightedText().color() : opt->palette.text().color());
232 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
233 if (pe == PE_FrameMenu || (frame->state & State_Sunken) || (frame->state & State_Raised)) {
234 qDrawShadePanel(p, frame->rect, frame->palette, frame->state & State_Sunken,
237 qDrawPlainRect(p, frame->rect, frame->palette.windowText().color(), frame->lineWidth);
241#if QT_CONFIG(toolbar)
242 case PE_PanelMenuBar:
243 if (widget && qobject_cast<QToolBar *>(widget->parentWidget()))
245 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)){
246 qDrawShadePanel(p, frame->rect, frame->palette,
false, frame->lineWidth,
247 &frame->palette.brush(QPalette::Button));
250 else if (
const QStyleOptionToolBar *frame = qstyleoption_cast<
const QStyleOptionToolBar *>(opt)){
251 qDrawShadePanel(p, frame->rect, frame->palette,
false, frame->lineWidth,
252 &frame->palette.brush(QPalette::Button));
258 case PE_PanelToolBar:
261#if QT_CONFIG(progressbar)
262 case PE_IndicatorProgressChunk:
264 bool vertical =
false;
265 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt))
266 vertical = !(pb->state & QStyle::State_Horizontal);
268 p->fillRect(opt->rect.x(), opt->rect.y() + 3, opt->rect.width() -2, opt->rect.height() - 6,
269 opt->palette.brush(QPalette::Highlight));
271 p->fillRect(opt->rect.x() + 2, opt->rect.y(), opt->rect.width() -6, opt->rect.height() - 2,
272 opt->palette.brush(QPalette::Highlight));
277 case PE_IndicatorBranch: {
278 static const int decoration_size = 9;
279 int mid_h = opt->rect.x() + opt->rect.width() / 2;
280 int mid_v = opt->rect.y() + opt->rect.height() / 2;
285 if (opt->state & State_Children) {
286 int delta = decoration_size / 2;
291 p->drawLine(bef_h + 2, bef_v + 4, bef_h + 6, bef_v + 4);
292 if (!(opt->state & State_Open))
293 p->drawLine(bef_h + 4, bef_v + 2, bef_h + 4, bef_v + 6);
294 QPen oldPen = p->pen();
295 p->setPen(opt->palette.dark().color());
296 p->drawRect(bef_h, bef_v, decoration_size - 1, decoration_size - 1);
299 QBrush brush(opt->palette.dark().color(), Qt::Dense4Pattern);
300 if (opt->state & State_Item) {
301 if (opt->direction == Qt::RightToLeft)
302 p->fillRect(opt->rect.left(), mid_v, bef_h - opt->rect.left(), 1, brush);
304 p->fillRect(aft_h, mid_v, opt->rect.right() - aft_h + 1, 1, brush);
306 if (opt->state & State_Sibling)
307 p->fillRect(mid_h, aft_v, 1, opt->rect.bottom() - aft_v + 1, brush);
308 if (opt->state & (State_Open | State_Children | State_Item | State_Sibling))
309 p->fillRect(mid_h, opt->rect.y(), 1, bef_v - opt->rect.y(), brush);
311 case PE_FrameStatusBarItem:
312 qDrawShadeRect(p, opt->rect, opt->palette,
true, 1, 0,
nullptr);
314 case PE_IndicatorHeaderArrow:
315 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
316 QPainterStateGuard psg(p, QPainterStateGuard::InitialState::NoSave);
317 if (header->sortIndicator & QStyleOptionHeader::SortUp) {
319 p->setPen(QPen(opt->palette.light(), 0));
320 p->drawLine(opt->rect.x() + opt->rect.width(), opt->rect.y(),
321 opt->rect.x() + opt->rect.width() / 2, opt->rect.y() + opt->rect.height());
322 p->setPen(QPen(opt->palette.dark(), 0));
323 const QPoint points[] = {
324 QPoint(opt->rect.x() + opt->rect.width() / 2, opt->rect.y() + opt->rect.height()),
325 QPoint(opt->rect.x(), opt->rect.y()),
326 QPoint(opt->rect.x() + opt->rect.width(), opt->rect.y()),
328 p->drawPolyline(points,
sizeof points /
sizeof *points);
329 }
else if (header->sortIndicator & QStyleOptionHeader::SortDown) {
331 p->setPen(QPen(opt->palette.light(), 0));
332 const QPoint points[] = {
333 QPoint(opt->rect.x(), opt->rect.y() + opt->rect.height()),
334 QPoint(opt->rect.x() + opt->rect.width(), opt->rect.y() + opt->rect.height()),
335 QPoint(opt->rect.x() + opt->rect.width() / 2, opt->rect.y()),
337 p->drawPolyline(points,
sizeof points /
sizeof *points);
338 p->setPen(QPen(opt->palette.dark(), 0));
339 p->drawLine(opt->rect.x(), opt->rect.y() + opt->rect.height(),
340 opt->rect.x() + opt->rect.width() / 2, opt->rect.y());
345 case PE_FrameTabBarBase:
346 if (
const QStyleOptionTabBarBase *tbb
347 = qstyleoption_cast<
const QStyleOptionTabBarBase *>(opt)) {
348 QPainterStateGuard psg(p);
349 switch (tbb->shape) {
350 case QTabBar::RoundedNorth:
351 case QTabBar::TriangularNorth:
352 p->setPen(QPen(tbb->palette.light(), 0));
353 p->drawLine(tbb->rect.topLeft(), tbb->rect.topRight());
355 case QTabBar::RoundedWest:
356 case QTabBar::TriangularWest:
357 p->setPen(QPen(tbb->palette.light(), 0));
358 p->drawLine(tbb->rect.topLeft(), tbb->rect.bottomLeft());
360 case QTabBar::RoundedSouth:
361 case QTabBar::TriangularSouth:
362 p->setPen(QPen(tbb->palette.shadow(), 0));
363 p->drawLine(tbb->rect.left(), tbb->rect.bottom(),
364 tbb->rect.right(), tbb->rect.bottom());
365 p->setPen(QPen(tbb->palette.dark(), 0));
366 p->drawLine(tbb->rect.left(), tbb->rect.bottom() - 1,
367 tbb->rect.right() - 1, tbb->rect.bottom() - 1);
369 case QTabBar::RoundedEast:
370 case QTabBar::TriangularEast:
371 p->setPen(QPen(tbb->palette.dark(), 0));
372 p->drawLine(tbb->rect.topRight(), tbb->rect.bottomRight());
377 case PE_IndicatorTabClose: {
378 if (d->tabBarcloseButtonIcon.isNull())
379 d->tabBarcloseButtonIcon = proxy()->standardIcon(QStyle::SP_TabCloseButton, opt, widget);
381 const int size = proxy()->pixelMetric(QStyle::PM_SmallIconSize, opt, widget);
382 QIcon::Mode mode = opt->state & State_Enabled ?
383 (opt->state & State_Raised ? QIcon::Active : QIcon::Normal)
385 if (!opt->state.testAnyFlags(State_Raised | State_Sunken | State_Selected))
386 mode = QIcon::Disabled;
388 QIcon::State state = opt->state & State_Sunken ? QIcon::On : QIcon::Off;
389 QPixmap pixmap = d->tabBarcloseButtonIcon.pixmap(QSize(size, size), QStyleHelper::getDpr(p), mode, state);
390 proxy()->drawItemPixmap(p, opt->rect, Qt::AlignCenter, pixmap);
396 case PE_FrameTabWidget:
398 qDrawWinPanel(p, opt->rect, opt->palette,
false,
nullptr);
400 case PE_FrameLineEdit:
401 proxy()->drawPrimitive(PE_Frame, opt, p, widget);
403#if QT_CONFIG(groupbox)
404 case PE_FrameGroupBox:
405 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
406 if (frame->features & QStyleOptionFrame::Flat) {
407 QRect fr = frame->rect;
408 QPoint p1(fr.x(), fr.y() + 1);
409 QPoint p2(fr.x() + fr.width(), p1.y());
410 qDrawShadeLine(p, p1, p2, frame->palette,
true,
411 frame->lineWidth, frame->midLineWidth);
413 qDrawShadeRect(p, frame->rect.x(), frame->rect.y(), frame->rect.width(),
414 frame->rect.height(), frame->palette,
true,
415 frame->lineWidth, frame->midLineWidth);
420#if QT_CONFIG(dockwidget)
421 case PE_FrameDockWidget:
422 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
423 int lw = frame->lineWidth;
425 lw = proxy()->pixelMetric(PM_DockWidgetFrameWidth, opt, widget);
427 qDrawShadePanel(p, frame->rect, frame->palette,
false, lw);
431#if QT_CONFIG(toolbar)
432 case PE_IndicatorToolBarHandle: {
433 QPainterStateGuard psg(p);
434 p->translate(opt->rect.x(), opt->rect.y());
435 if (opt->state & State_Horizontal) {
436 int x = opt->rect.width() / 3;
437 if (opt->direction == Qt::RightToLeft)
439 if (opt->rect.height() > 4) {
440 qDrawShadePanel(p, x, 2, 3, opt->rect.height() - 4,
441 opt->palette,
false, 1,
nullptr);
442 qDrawShadePanel(p, x+3, 2, 3, opt->rect.height() - 4,
443 opt->palette,
false, 1,
nullptr);
446 if (opt->rect.width() > 4) {
447 int y = opt->rect.height() / 3;
448 qDrawShadePanel(p, 2, y, opt->rect.width() - 4, 3,
449 opt->palette,
false, 1,
nullptr);
450 qDrawShadePanel(p, 2, y+3, opt->rect.width() - 4, 3,
451 opt->palette,
false, 1,
nullptr);
456 case PE_IndicatorToolBarSeparator:
459 if (opt->state & State_Horizontal) {
460 p1 = QPoint(opt->rect.width()/2, 0);
461 p2 = QPoint(p1.x(), opt->rect.height());
463 p1 = QPoint(0, opt->rect.height()/2);
464 p2 = QPoint(opt->rect.width(), p1.y());
466 qDrawShadeLine(p, p1, p2, opt->palette, 1, 1, 0);
470#if QT_CONFIG(spinbox)
471 case PE_IndicatorSpinPlus:
472 case PE_IndicatorSpinMinus: {
474 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget);
475 QRect br = r.adjusted(fw, fw, -fw, -fw);
480 QPainterStateGuard psg(p);
481 const qreal devicePixelRatio = QStyleHelper::getDpr(p);
482 if (!qFuzzyCompare(devicePixelRatio, qreal(1))) {
483 const qreal inverseScale = qreal(1) / devicePixelRatio;
484 p->scale(inverseScale, inverseScale);
485 x = qRound(devicePixelRatio * x);
486 y = qRound(devicePixelRatio * y);
487 w = qRound(devicePixelRatio * w);
488 h = qRound(devicePixelRatio * h);
489 p->translate(0.5, 0.5);
491 int len = std::min(w, h);
494 int step = (len + 4) / 5;
497 const int step2 = step / 2;
498 QPoint center(x + w / 2, y + h / 2);
499 if (opt->state & State_Sunken) {
500 center += QPoint(proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget),
501 proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget));
503 p->translate(center);
504 p->fillRect(-len / 2, -step2, len, step, opt->palette.buttonText());
505 if (pe == PE_IndicatorSpinPlus)
506 p->fillRect(-step2, -len / 2, step, len, opt->palette.buttonText());
508 case PE_IndicatorSpinUp:
509 case PE_IndicatorSpinDown: {
511 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget);
517 QPainterStateGuard psg(p);
518 const qreal devicePixelRatio = QStyleHelper::getDpr(p);
519 if (!qFuzzyCompare(devicePixelRatio, qreal(1))) {
520 const qreal inverseScale = qreal(1) / devicePixelRatio;
521 p->scale(inverseScale, inverseScale);
522 x = qRound(devicePixelRatio * x);
523 y = qRound(devicePixelRatio * y);
524 w = qRound(devicePixelRatio * w);
525 h = qRound(devicePixelRatio * h);
526 p->translate(0.5, 0.5);
536 int sx = x + w / 2 - sw / 2;
537 int sy = y + h / 2 - sh / 2;
539 if (pe == PE_IndicatorSpinUp && fw)
544 if (opt->state & State_Sunken) {
545 bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget);
546 bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget);
548 p->translate(sx + bsx, sy + bsy);
549 p->setPen(opt->palette.buttonText().color());
550 p->setBrush(opt->palette.buttonText());
551 if (pe == PE_IndicatorSpinDown) {
552 const QPoint points[] = { QPoint(0, 1), QPoint(sw-1, 1), QPoint(sh-2, sh-1) };
553 p->drawPolygon(points,
sizeof points /
sizeof *points);
555 const QPoint points[] = { QPoint(0, sh-1), QPoint(sw-1, sh-1), QPoint(sh-2, 1) };
556 p->drawPolygon(points,
sizeof points /
sizeof *points);
560 case PE_PanelTipLabel: {
561 const QBrush brush(opt->palette.toolTipBase());
562 qDrawPlainRect(p, opt->rect, opt->palette.toolTipText().color(), 1, &brush);
566 case PE_IndicatorTabTear:
567 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
568 bool rtl = tab->direction == Qt::RightToLeft;
569 const bool horizontal = tab->rect.height() > tab->rect.width();
570 const bool isSelected = tab->state.testFlag(State_Selected);
571 const int margin = 4;
575 QRect rect = tab->rect.adjusted(rtl ? margin : 0, 0, rtl ? 1 : -margin, 0);
576 rect.setTop(rect.top() + (isSelected ? 1 : 3));
577 rect.setBottom(rect.bottom() - (isSelected ? 0 : 2));
579 path.moveTo(QPoint(rtl ? rect.right() : rect.left(), rect.top()));
581 for (
int jags = 1; jags <= count; ++jags, rtl = !rtl)
582 path.lineTo(QPoint(rtl ? rect.left() : rect.right(), rect.top() + jags * rect.height()/count));
584 QRect rect = tab->rect.adjusted(0, 0, 0, -margin);
585 rect.setLeft(rect.left() + (isSelected ? 1 : 3));
586 rect.setRight(rect.right() - (isSelected ? 0 : 2));
588 path.moveTo(QPoint(rect.left(), rect.top()));
590 for (
int jags = 1; jags <= count; ++jags, rtl = !rtl)
591 path.lineTo(QPoint(rect.left() + jags * rect.width()/count, rtl ? rect.top() : rect.bottom()));
594 p->setPen(QPen(tab->palette.dark(), qreal(.8)));
595 p->setBrush(tab->palette.window());
596 p->setRenderHint(QPainter::Antialiasing);
601#if QT_CONFIG(lineedit)
602 case PE_PanelLineEdit:
603 if (
const QStyleOptionFrame *panel = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
604 p->fillRect(panel->rect.adjusted(panel->lineWidth, panel->lineWidth, -panel->lineWidth, -panel->lineWidth),
605 panel->palette.brush(QPalette::Base));
607 if (panel->lineWidth > 0)
608 proxy()->drawPrimitive(PE_FrameLineEdit, panel, p, widget);
612#if QT_CONFIG(columnview)
613 case PE_IndicatorColumnViewArrow: {
614 if (
const QStyleOptionViewItem *viewOpt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
615 bool reverse = (viewOpt->direction == Qt::RightToLeft);
616 QPainterStateGuard psg(p);
618 int x = viewOpt->rect.x() + 1;
619 int offset = (viewOpt->rect.height() / 3);
620 int height = (viewOpt->rect.height()) - offset * 2;
623 int x2 = x + height - 1;
625 x = viewOpt->rect.x() + viewOpt->rect.width() - 1;
628 path.moveTo(x, viewOpt->rect.y() + offset);
629 path.lineTo(x, viewOpt->rect.y() + offset + height);
630 path.lineTo(x2, viewOpt->rect.y() + offset+height/2);
632 if (viewOpt->state & QStyle::State_Selected ) {
633 if (viewOpt->showDecorationSelected) {
634 QColor color = viewOpt->palette.color(QPalette::Active, QPalette::HighlightedText);
638 QColor color = viewOpt->palette.color(QPalette::Active, QPalette::WindowText);
644 QColor color = viewOpt->palette.color(QPalette::Active, QPalette::Mid);
651 if (!(viewOpt->state & QStyle::State_Selected)) {
653 lines.moveTo(x, viewOpt->rect.y() + offset);
654 lines.lineTo(x, viewOpt->rect.y() + offset + height);
655 lines.moveTo(x, viewOpt->rect.y() + offset);
656 lines.lineTo(x2, viewOpt->rect.y() + offset+height/2);
657 QColor color = viewOpt->palette.color(QPalette::Active, QPalette::Dark);
664 case PE_IndicatorItemViewItemDrop: {
665 QRect rect = opt->rect;
666 if (opt->rect.height() == 0)
667 p->drawLine(rect.topLeft(), rect.topRight());
671#if QT_CONFIG(itemviews)
672 case PE_PanelItemViewRow:
673 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
674 QPalette::ColorGroup cg = (widget ? widget->isEnabled() : (vopt->state & QStyle::State_Enabled))
675 ? QPalette::Normal : QPalette::Disabled;
676 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))
677 cg = QPalette::Inactive;
679 if ((vopt->state & QStyle::State_Selected) && vopt->showDecorationSelected)
680 p->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::Highlight));
681 else if (vopt->features & QStyleOptionViewItem::Alternate)
682 p->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::AlternateBase));
685 case PE_PanelItemViewItem:
686 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
687 QPalette::ColorGroup cg = (widget ? widget->isEnabled() : (vopt->state & QStyle::State_Enabled))
688 ? QPalette::Normal : QPalette::Disabled;
689 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))
690 cg = QPalette::Inactive;
692 if (vopt->showDecorationSelected && (vopt->state & QStyle::State_Selected)) {
693 p->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::Highlight));
695 if (vopt->backgroundBrush.style() != Qt::NoBrush) {
696 QPainterStateGuard psg(p);
697 p->setBrushOrigin(vopt->rect.topLeft());
698 p->fillRect(vopt->rect, vopt->backgroundBrush);
701 if (vopt->state & QStyle::State_Selected) {
702 QRect textRect = subElementRect(QStyle::SE_ItemViewItemText, opt, widget);
703 p->fillRect(textRect, vopt->palette.brush(cg, QPalette::Highlight));
709 case PE_PanelScrollAreaCorner: {
710 const QBrush brush(opt->palette.brush(QPalette::Window));
711 p->fillRect(opt->rect, brush);
713 case PE_IndicatorArrowUp:
714 case PE_IndicatorArrowDown:
715 case PE_IndicatorArrowRight:
716 case PE_IndicatorArrowLeft:
718 const QRect &r = opt->rect;
719 if (r.width() <= 1 || r.height() <= 1)
721 int size = qMin(r.height(), r.width());
723 const qreal dpr = QStyleHelper::getDpr(p);
724 const QString pixmapName = QStyleHelper::uniqueName(
"$qt_ia-"_L1
725 % QLatin1StringView(metaObject()->className())
726 % HexString<uint>(pe),
727 opt, QSize(size, size), dpr);
728 if (!QPixmapCache::find(pixmapName, &pixmap)) {
730 const int border = 1 * dpr;
731 const int sizeDpr = size * dpr;
732 int width = sizeDpr - 2 * border - 1;
733 int height = width / 2;
734 const int add = ((width & 1) == 1);
735 if (pe == PE_IndicatorArrowRight || pe == PE_IndicatorArrowLeft)
736 std::swap(width, height);
737 pixmap = styleCachePixmap(QSize(sizeDpr, sizeDpr), 1);
739 std::array<QPointF, 4> poly;
741 case PE_IndicatorArrowUp:
742 poly = {QPointF(0, height), QPointF(width, height),
743 QPointF(width / 2 + add, 0), QPointF(width / 2, 0)};
745 case PE_IndicatorArrowDown:
746 poly = {QPointF(0, 0), QPointF(width, 0),
747 QPointF(width / 2 + add, height), QPointF(width / 2, height)};
749 case PE_IndicatorArrowRight:
750 poly = {QPointF(0, 0), QPointF(0, height),
751 QPointF(width, height / 2 + add), QPointF(width, height / 2)};
753 case PE_IndicatorArrowLeft:
754 poly = {QPointF(width, 0), QPointF(width, height),
755 QPointF(0, height / 2 + add), QPointF(0, height / 2)};
761 QPainter imagePainter(&pixmap);
762 imagePainter.translate((sizeDpr - width) / 2, (sizeDpr - height) / 2);
763 if (opt->state & State_Sunken) {
764 const auto bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget);
765 const auto bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget);
766 imagePainter.translate(bsx, bsy);
768 imagePainter.setPen(opt->palette.buttonText().color());
769 imagePainter.setBrush(opt->palette.buttonText());
771 if (!(opt->state & State_Enabled)) {
772 const int ofs = qRound(1 * dpr);
773 imagePainter.translate(ofs, ofs);
774 imagePainter.setBrush(opt->palette.light());
775 imagePainter.setPen(opt->palette.light().color());
776 imagePainter.drawPolygon(poly.data(),
int(poly.size()));
777 imagePainter.drawPoints(poly.data(),
int(poly.size()));
778 imagePainter.translate(-ofs, -ofs);
779 imagePainter.setBrush(opt->palette.mid());
780 imagePainter.setPen(opt->palette.mid().color());
782 imagePainter.drawPolygon(poly.data(),
int(poly.size()));
784 imagePainter.drawPoints(poly.data(),
int(poly.size()));
786 pixmap.setDevicePixelRatio(dpr);
787 QPixmapCache::insert(pixmapName, pixmap);
789 int xOffset = r.x() + (r.width() - size)/2;
790 int yOffset = r.y() + (r.height() - size)/2;
791 p->drawPixmap(xOffset, yOffset, pixmap);
1278void QCommonStyle::drawControl(ControlElement element,
const QStyleOption *opt,
1279 QPainter *p,
const QWidget *widget)
const
1281 Q_D(
const QCommonStyle);
1285 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
1286 proxy()->drawControl(CE_PushButtonBevel, btn, p, widget);
1287 QStyleOptionButton subopt = *btn;
1288 subopt.rect = subElementRect(SE_PushButtonContents, btn, widget);
1289 proxy()->drawControl(CE_PushButtonLabel, &subopt, p, widget);
1290 if (btn->state & State_HasFocus) {
1291 QStyleOptionFocusRect fropt;
1292 fropt.QStyleOption::operator=(*btn);
1293 fropt.rect = subElementRect(SE_PushButtonFocusRect, btn, widget);
1294 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
1298 case CE_PushButtonBevel:
1299 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
1300 QRect br = btn->rect;
1301 int dbi = proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
1302 if (btn->features & QStyleOptionButton::DefaultButton)
1303 proxy()->drawPrimitive(PE_FrameDefaultButton, opt, p, widget);
1304 if (btn->features & QStyleOptionButton::AutoDefaultButton)
1305 br.setCoords(br.left() + dbi, br.top() + dbi, br.right() - dbi, br.bottom() - dbi);
1306 if (!(btn->features & (QStyleOptionButton::Flat | QStyleOptionButton::CommandLinkButton))
1307 || btn->state & (State_Sunken | State_On)
1308 || (btn->features & QStyleOptionButton::CommandLinkButton && btn->state & State_MouseOver)) {
1309 QStyleOptionButton tmpBtn = *btn;
1311 proxy()->drawPrimitive(PE_PanelButtonCommand, &tmpBtn, p, widget);
1313 if (btn->features & QStyleOptionButton::HasMenu) {
1314 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, btn, widget);
1315 QRect ir = btn->rect;
1316 QStyleOptionButton newBtn = *btn;
1317 newBtn.rect = QRect(ir.right() - mbi - 2, ir.height()/2 - mbi/2 + 3, mbi - 6, mbi - 6);
1318 newBtn.rect = visualRect(btn->direction, br, newBtn.rect);
1319 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, p, widget);
1323 case CE_PushButtonLabel:
1324 if (
const QStyleOptionButton *button = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
1325 QRect textRect = button->rect;
1326 int tf = Qt::AlignVCenter | Qt::TextShowMnemonic;
1327 if (!proxy()->styleHint(SH_UnderlineShortcut, button, widget))
1328 tf |= Qt::TextHideMnemonic;
1330 if (button->features & QStyleOptionButton::HasMenu) {
1331 int indicatorSize = proxy()->pixelMetric(PM_MenuButtonIndicator, button, widget);
1332 if (button->direction == Qt::LeftToRight)
1333 textRect = textRect.adjusted(0, 0, -indicatorSize, 0);
1335 textRect = textRect.adjusted(indicatorSize, 0, 0, 0);
1338 if (!button->icon.isNull()) {
1340 QIcon::Mode mode = button->state & State_Enabled ? QIcon::Normal : QIcon::Disabled;
1341 if (mode == QIcon::Normal && button->state & State_HasFocus)
1342 mode = QIcon::Active;
1343 QIcon::State state = QIcon::Off;
1344 if (button->state & State_On)
1347 QPixmap pixmap = button->icon.pixmap(button->iconSize, QStyleHelper::getDpr(p), mode, state);
1348 int pixmapWidth = pixmap.width() / pixmap.devicePixelRatio();
1349 int pixmapHeight = pixmap.height() / pixmap.devicePixelRatio();
1350 int labelWidth = pixmapWidth;
1351 int labelHeight = pixmapHeight;
1352 int iconSpacing = 4;
1353 if (!button->text.isEmpty()) {
1354 int textWidth = button->fontMetrics.boundingRect(opt->rect, tf, button->text).width();
1355 labelWidth += (textWidth + iconSpacing);
1358 QRect iconRect = QRect(textRect.x() + (textRect.width() - labelWidth) / 2,
1359 textRect.y() + (textRect.height() - labelHeight) / 2,
1360 pixmapWidth, pixmapHeight);
1362 iconRect = visualRect(button->direction, textRect, iconRect);
1364 if (button->direction == Qt::RightToLeft)
1365 textRect.setRight(iconRect.left() - iconSpacing / 2);
1367 textRect.setLeft(iconRect.left() + iconRect.width() + iconSpacing / 2);
1370 if (p->layoutDirection() == button->direction)
1371 tf |= Qt::AlignLeft;
1373 tf |= Qt::AlignRight;
1375 if (button->state & (State_On | State_Sunken))
1376 iconRect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget),
1377 proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget));
1378 p->drawPixmap(iconRect.x(), iconRect.y(), pixmap);
1380 tf |= Qt::AlignHCenter;
1382 if (button->state & (State_On | State_Sunken))
1383 textRect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget),
1384 proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget));
1386 proxy()->drawItemText(p, textRect, tf, button->palette, (button->state & State_Enabled),
1387 button->text, QPalette::ButtonText);
1390 case CE_RadioButton:
1392 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
1393 bool isRadio = (element == CE_RadioButton);
1394 QStyleOptionButton subopt = *btn;
1395 subopt.rect = subElementRect(isRadio ? SE_RadioButtonIndicator
1396 : SE_CheckBoxIndicator, btn, widget);
1397 proxy()->drawPrimitive(isRadio ? PE_IndicatorRadioButton : PE_IndicatorCheckBox,
1398 &subopt, p, widget);
1399 subopt.rect = subElementRect(isRadio ? SE_RadioButtonContents
1400 : SE_CheckBoxContents, btn, widget);
1401 proxy()->drawControl(isRadio ? CE_RadioButtonLabel : CE_CheckBoxLabel, &subopt, p, widget);
1402 if (btn->state & State_HasFocus) {
1403 QStyleOptionFocusRect fropt;
1404 fropt.QStyleOption::operator=(*btn);
1405 fropt.rect = subElementRect(isRadio ? SE_RadioButtonFocusRect
1406 : SE_CheckBoxFocusRect, btn, widget);
1407 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
1411 case CE_RadioButtonLabel:
1412 case CE_CheckBoxLabel:
1413 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
1414 int alignment = visualAlignment(btn->direction, Qt::AlignLeft | Qt::AlignVCenter);
1416 if (!proxy()->styleHint(SH_UnderlineShortcut, btn, widget))
1417 alignment |= Qt::TextHideMnemonic;
1418 QRect textRect = btn->rect;
1419 if (!btn->icon.isNull()) {
1420 const auto pix = btn->icon.pixmap(btn->iconSize, QStyleHelper::getDpr(p),
1421 btn->state & State_Enabled ? QIcon::Normal : QIcon::Disabled);
1422 proxy()->drawItemPixmap(p, btn->rect, alignment, pix);
1423 if (btn->direction == Qt::RightToLeft)
1424 textRect.setRight(textRect.right() - btn->iconSize.width() - 4);
1426 textRect.setLeft(textRect.left() + btn->iconSize.width() + 4);
1428 if (!btn->text.isEmpty()){
1429 proxy()->drawItemText(p, textRect, alignment | Qt::TextShowMnemonic,
1430 btn->palette, btn->state & State_Enabled, btn->text, QPalette::WindowText);
1435 case CE_MenuScroller: {
1436 QStyleOption arrowOpt = *opt;
1437 arrowOpt.state |= State_Enabled;
1438 proxy()->drawPrimitive(((opt->state & State_DownArrow) ? PE_IndicatorArrowDown : PE_IndicatorArrowUp),
1439 &arrowOpt, p, widget);
1441 case CE_MenuTearoff:
1442 if (opt->state & State_Selected)
1443 p->fillRect(opt->rect, opt->palette.brush(QPalette::Highlight));
1445 p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));
1446 p->setPen(QPen(opt->palette.dark().color(), 1, Qt::DashLine));
1447 p->drawLine(opt->rect.x() + 2, opt->rect.y() + opt->rect.height() / 2 - 1,
1448 opt->rect.x() + opt->rect.width() - 4,
1449 opt->rect.y() + opt->rect.height() / 2 - 1);
1450 p->setPen(QPen(opt->palette.light().color(), 1, Qt::DashLine));
1451 p->drawLine(opt->rect.x() + 2, opt->rect.y() + opt->rect.height() / 2,
1452 opt->rect.x() + opt->rect.width() - 4, opt->rect.y() + opt->rect.height() / 2);
1455#if QT_CONFIG(menubar)
1456 case CE_MenuBarItem:
1457 if (
const QStyleOptionMenuItem *mbi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
1458 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip
1459 | Qt::TextSingleLine;
1460 if (!proxy()->styleHint(SH_UnderlineShortcut, mbi, widget))
1461 alignment |= Qt::TextHideMnemonic;
1462 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
1463 QPixmap pix = mbi->icon.pixmap(QSize(iconExtent, iconExtent), QStyleHelper::getDpr(p), (mbi->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled);
1465 proxy()->drawItemPixmap(p,mbi->rect, alignment, pix);
1467 proxy()->drawItemText(p, mbi->rect, alignment, mbi->palette, mbi->state & State_Enabled,
1468 mbi->text, QPalette::ButtonText);
1471 case CE_MenuBarEmptyArea:
1472 if (widget && !widget->testAttribute(Qt::WA_NoSystemBackground))
1473 p->eraseRect(opt->rect);
1476#if QT_CONFIG(progressbar)
1477 case CE_ProgressBar:
1478 if (
const QStyleOptionProgressBar *pb
1479 = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
1480 QStyleOptionProgressBar subopt = *pb;
1481 subopt.rect = subElementRect(SE_ProgressBarGroove, pb, widget);
1482 proxy()->drawControl(CE_ProgressBarGroove, &subopt, p, widget);
1483 subopt.rect = subElementRect(SE_ProgressBarContents, pb, widget);
1484 proxy()->drawControl(CE_ProgressBarContents, &subopt, p, widget);
1485 if (pb->textVisible) {
1486 subopt.rect = subElementRect(SE_ProgressBarLabel, pb, widget);
1487 proxy()->drawControl(CE_ProgressBarLabel, &subopt, p, widget);
1491 case CE_ProgressBarGroove:
1492 if (opt->rect.isValid())
1493 qDrawShadePanel(p, opt->rect, opt->palette,
true, 1,
1494 &opt->palette.brush(QPalette::Window));
1496 case CE_ProgressBarLabel:
1497 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
1498 const bool vertical = !(pb->state & QStyle::State_Horizontal);
1500 QPalette::ColorRole textRole = QPalette::NoRole;
1501 if ((pb->textAlignment & Qt::AlignCenter) && pb->textVisible
1502 && ((qint64(pb->progress) - qint64(pb->minimum)) * 2 >= (qint64(pb->maximum) - qint64(pb->minimum)))) {
1503 textRole = QPalette::HighlightedText;
1505 QRect shadowRect(pb->rect);
1506 shadowRect.translate(1,1);
1507 QColor shadowColor = (pb->palette.color(textRole).value() <= 128)
1508 ? QColor(255,255,255,160) : QColor(0,0,0,160);
1509 QPalette shadowPalette = pb->palette;
1510 shadowPalette.setColor(textRole, shadowColor);
1511 proxy()->drawItemText(p, shadowRect, Qt::AlignCenter | Qt::TextSingleLine, shadowPalette,
1512 pb->state & State_Enabled, pb->text, textRole);
1514 proxy()->drawItemText(p, pb->rect, Qt::AlignCenter | Qt::TextSingleLine, pb->palette,
1515 pb->state & State_Enabled, pb->text, textRole);
1519 case CE_ProgressBarContents:
1520 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
1522 QRect rect = pb->rect;
1523 const bool vertical = !(pb->state & QStyle::State_Horizontal);
1524 const bool inverted = pb->invertedAppearance;
1525 qint64 minimum = qint64(pb->minimum);
1526 qint64 maximum = qint64(pb->maximum);
1527 qint64 progress = qint64(pb->progress);
1532 rect = QRect(rect.y(), rect.x(), rect.height(), rect.width());
1534 m.translate(0, -(rect.height() + rect.y()*2));
1537 QPalette pal2 = pb->palette;
1539 if (pal2.highlight() == pal2.window())
1540 pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active,
1541 QPalette::Highlight));
1542 bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical);
1545 int w = rect.width();
1546 if (pb->minimum == 0 && pb->maximum == 0) {
1548 int x = (progress - minimum) % (w * 2);
1551 x = reverse ? rect.right() - x : x + rect.x();
1552 p->setPen(QPen(pal2.highlight().color(), 4));
1553 p->drawLine(x, rect.y(), x, rect.height());
1555 const int unit_width = proxy()->pixelMetric(PM_ProgressBarChunkWidth, pb, widget);
1561 u = ((rect.width() + unit_width) / unit_width);
1564 qint64 p_v = progress - minimum;
1565 qint64 t_s = (maximum - minimum) ? (maximum - minimum) : qint64(1);
1567 if (u > 0 && p_v >= INT_MAX / u && t_s >= u) {
1575 tnu = nu = p_v * u / t_s;
1577 if (nu * unit_width > w)
1585 int x0 = reverse ? rect.right() - ((unit_width > 1) ? unit_width : 0)
1588 QStyleOptionProgressBar pbBits = *pb;
1590 pbBits.palette = pal2;
1591 int myY = pbBits.rect.y();
1592 int myHeight = pbBits.rect.height();
1593 pbBits.state &= QStyle::State_Horizontal;
1594 for (
int i = 0; i < nu; ++i) {
1595 pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);
1596 pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();
1597 proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
1598 x += reverse ? -unit_width : unit_width;
1604 int pixels_left = w - (nu * unit_width);
1605 int offset = reverse ? x0 + x + unit_width-pixels_left : x0 + x;
1606 pbBits.rect.setRect(offset, myY, pixels_left, myHeight);
1607 pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();
1608 proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
1614 case CE_HeaderLabel:
1615 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
1616 QRect rect = header->rect;
1617 if (!header->icon.isNull()) {
1618 const int iconExtent = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
1619 const QRect aligned = alignedRect(header->direction, header->iconAlignment,
1620 QSize(iconExtent, iconExtent), rect);
1621 header->icon.paint(p, aligned, Qt::AlignCenter,
1622 header->state.testFlag(State_Enabled) ? QIcon::Normal
1625 const int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget);
1626 if (header->direction == Qt::LeftToRight)
1627 rect.setLeft(rect.left() + iconExtent + margin);
1629 rect.setRight(rect.right() - iconExtent - margin);
1631 QFontMetrics fm(header->fontMetrics);
1632 if (header->state & QStyle::State_On) {
1633 QFont fnt = p->font();
1635 if (!(fnt.resolveMask() & QFont::WeightResolved)) {
1638 fm = QFontMetrics((p->font()));
1641 QString text = header->text;
1642 if (
const QStyleOptionHeaderV2 *headerV2 = qstyleoption_cast<
const QStyleOptionHeaderV2 *>(header)) {
1643 if (headerV2->textElideMode != Qt::ElideNone)
1644 text = fm.elidedText(header->text, headerV2->textElideMode, rect.width());
1646 proxy()->drawItemText(p, rect, header->textAlignment, header->palette,
1647 header->state.testFlag(State_Enabled), text, QPalette::ButtonText);
1650#if QT_CONFIG(toolbutton)
1651 case CE_ToolButtonLabel:
1652 if (
const QStyleOptionToolButton *toolbutton
1653 = qstyleoption_cast<
const QStyleOptionToolButton *>(opt)) {
1654 QRect rect = toolbutton->rect;
1657 if (toolbutton->state & (State_Sunken | State_On)) {
1658 shiftX = proxy()->pixelMetric(PM_ButtonShiftHorizontal, toolbutton, widget);
1659 shiftY = proxy()->pixelMetric(PM_ButtonShiftVertical, toolbutton, widget);
1662 bool hasArrow = toolbutton->features & QStyleOptionToolButton::Arrow;
1663 if (((!hasArrow && toolbutton->icon.isNull()) && !toolbutton->text.isEmpty())
1664 || toolbutton->toolButtonStyle == Qt::ToolButtonTextOnly) {
1665 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;
1666 if (!proxy()->styleHint(SH_UnderlineShortcut, opt, widget))
1667 alignment |= Qt::TextHideMnemonic;
1668 rect.translate(shiftX, shiftY);
1669 p->setFont(toolbutton->font);
1670 const QString text = d->toolButtonElideText(toolbutton, rect, alignment);
1671 proxy()->drawItemText(p, rect, alignment, toolbutton->palette,
1672 opt->state & State_Enabled, text,
1673 QPalette::ButtonText);
1676 QSize pmSize = toolbutton->iconSize;
1677 if (!toolbutton->icon.isNull()) {
1678 QIcon::State state = toolbutton->state & State_On ? QIcon::On : QIcon::Off;
1680 if (!(toolbutton->state & State_Enabled))
1681 mode = QIcon::Disabled;
1682 else if ((opt->state & State_MouseOver) && (opt->state & State_AutoRaise))
1683 mode = QIcon::Active;
1685 mode = QIcon::Normal;
1686 pm = toolbutton->icon.pixmap(toolbutton->rect.size().boundedTo(toolbutton->iconSize), QStyleHelper::getDpr(p),
1688 pmSize = pm.size() / pm.devicePixelRatio();
1691 if (toolbutton->toolButtonStyle != Qt::ToolButtonIconOnly) {
1692 p->setFont(toolbutton->font);
1695 int alignment = Qt::TextShowMnemonic;
1696 if (!proxy()->styleHint(SH_UnderlineShortcut, opt, widget))
1697 alignment |= Qt::TextHideMnemonic;
1699 if (toolbutton->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
1700 pr.setHeight(pmSize.height() + 4);
1701 tr.adjust(0, pr.height() - 1, 0, -1);
1702 pr.translate(shiftX, shiftY);
1704 proxy()->drawItemPixmap(p, pr, Qt::AlignCenter, pm);
1706 drawArrow(proxy(), toolbutton, pr, p, widget);
1708 alignment |= Qt::AlignCenter;
1710 pr.setWidth(pmSize.width() + 4);
1711 tr.adjust(pr.width(), 0, 0, 0);
1712 pr.translate(shiftX, shiftY);
1714 proxy()->drawItemPixmap(p, QStyle::visualRect(opt->direction, rect, pr), Qt::AlignCenter, pm);
1716 drawArrow(proxy(), toolbutton, pr, p, widget);
1718 alignment |= Qt::AlignLeft | Qt::AlignVCenter;
1720 tr.translate(shiftX, shiftY);
1721 const QString text = d->toolButtonElideText(toolbutton, tr, alignment);
1722 proxy()->drawItemText(p, QStyle::visualRect(opt->direction, rect, tr), alignment, toolbutton->palette,
1723 toolbutton->state & State_Enabled, text,
1724 QPalette::ButtonText);
1726 rect.translate(shiftX, shiftY);
1728 drawArrow(proxy(), toolbutton, rect, p, widget);
1730 proxy()->drawItemPixmap(p, rect, Qt::AlignCenter, pm);
1737#if QT_CONFIG(toolbox)
1739 if (
const QStyleOptionToolBox *tb = qstyleoption_cast<
const QStyleOptionToolBox *>(opt)) {
1740 proxy()->drawControl(CE_ToolBoxTabShape, tb, p, widget);
1741 proxy()->drawControl(CE_ToolBoxTabLabel, tb, p, widget);
1744 case CE_ToolBoxTabShape:
1745 if (
const QStyleOptionToolBox *tb = qstyleoption_cast<
const QStyleOptionToolBox *>(opt)) {
1746 p->setPen(tb->palette.mid().color().darker(150));
1747 int d = 20 + tb->rect.height() - 3;
1748 if (tb->direction != Qt::RightToLeft) {
1749 const QPoint points[] = {
1750 QPoint(-1, tb->rect.height() + 1),
1752 QPoint(tb->rect.width() - d, 1),
1753 QPoint(tb->rect.width() - 20, tb->rect.height() - 2),
1754 QPoint(tb->rect.width() - 1, tb->rect.height() - 2),
1755 QPoint(tb->rect.width() - 1, tb->rect.height() + 1),
1756 QPoint(-1, tb->rect.height() + 1),
1758 p->drawPolygon(points,
sizeof points /
sizeof *points);
1760 const QPoint points[] = {
1761 QPoint(tb->rect.width(), tb->rect.height() + 1),
1762 QPoint(tb->rect.width(), 1),
1764 QPoint(20 - 1, tb->rect.height() - 2),
1765 QPoint(0, tb->rect.height() - 2),
1766 QPoint(0, tb->rect.height() + 1),
1767 QPoint(tb->rect.width(), tb->rect.height() + 1),
1769 p->drawPolygon(points,
sizeof points /
sizeof *points);
1771 p->setPen(tb->palette.light().color());
1772 if (tb->direction != Qt::RightToLeft) {
1773 p->drawLine(0, 2, tb->rect.width() - d, 2);
1774 p->drawLine(tb->rect.width() - d - 1, 2, tb->rect.width() - 21, tb->rect.height() - 1);
1775 p->drawLine(tb->rect.width() - 20, tb->rect.height() - 1,
1776 tb->rect.width(), tb->rect.height() - 1);
1778 p->drawLine(tb->rect.width() - 1, 2, d - 1, 2);
1779 p->drawLine(d, 2, 20, tb->rect.height() - 1);
1780 p->drawLine(19, tb->rect.height() - 1,
1781 -1, tb->rect.height() - 1);
1783 p->setBrush(Qt::NoBrush);
1787#if QT_CONFIG(tabbar)
1789 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
1790 proxy()->drawControl(CE_TabBarTabShape, tab, p, widget);
1791 proxy()->drawControl(CE_TabBarTabLabel, tab, p, widget);
1794 case CE_TabBarTabShape:
1795 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
1796 QPainterStateGuard psg(p);
1797 QRect rect(tab->rect);
1798 bool selected = tab->state & State_Selected;
1799 bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
1800 int tabOverlap = onlyOne ? 0 : proxy()->pixelMetric(PM_TabBarTabOverlap, opt, widget);
1803 switch (tab->shape) {
1804 case QTabBar::TriangularNorth:
1805 rect.adjust(0, 0, 0, -tabOverlap);
1807 rect.adjust(1, 1, -1, 0);
1809 case QTabBar::TriangularSouth:
1810 rect.adjust(0, tabOverlap, 0, 0);
1812 rect.adjust(1, 0, -1, -1);
1814 case QTabBar::TriangularEast:
1815 rect.adjust(tabOverlap, 0, 0, 0);
1817 rect.adjust(0, 1, -1, -1);
1819 case QTabBar::TriangularWest:
1820 rect.adjust(0, 0, -tabOverlap, 0);
1822 rect.adjust(1, 1, 0, -1);
1829 p->setPen(QPen(tab->palette.windowText(), 0));
1831 p->setBrush(tab->palette.base());
1833 if (widget && widget->parentWidget())
1834 p->setBrush(widget->parentWidget()->palette().window());
1836 p->setBrush(tab->palette.window());
1842 switch (tab->shape) {
1843 case QTabBar::TriangularNorth:
1844 case QTabBar::TriangularSouth: {
1845 a.setPoint(0, 0, -1);
1846 a.setPoint(1, 0, 0);
1847 y = rect.height() - 2;
1849 a.setPoint(2, x++, y - 1);
1851 a.setPoint(3, x++, y++);
1852 a.setPoint(4, x, y);
1855 int right = rect.width() - 1;
1856 for (i = 0; i < 5; ++i)
1857 a.setPoint(9 - i, right - a.point(i).x(), a.point(i).y());
1858 if (tab->shape == QTabBar::TriangularNorth)
1859 for (i = 0; i < 10; ++i)
1860 a.setPoint(i, a.point(i).x(), rect.height() - 1 - a.point(i).y());
1862 a.translate(rect.left(), rect.top());
1863 p->setRenderHint(QPainter::Antialiasing);
1864 p->translate(0, 0.5);
1870 case QTabBar::TriangularEast:
1871 case QTabBar::TriangularWest: {
1872 a.setPoint(0, -1, 0);
1873 a.setPoint(1, 0, 0);
1874 x = rect.width() - 2;
1876 a.setPoint(2, x - 1, y++);
1878 a.setPoint(3, x++, y++);
1879 a.setPoint(4, x, y);
1881 int bottom = rect.height() - 1;
1882 for (i = 0; i < 5; ++i)
1883 a.setPoint(9 - i, a.point(i).x(), bottom - a.point(i).y());
1884 if (tab->shape == QTabBar::TriangularWest)
1885 for (i = 0; i < 10; ++i)
1886 a.setPoint(i, rect.width() - 1 - a.point(i).x(), a.point(i).y());
1887 a.translate(rect.left(), rect.top());
1888 p->setRenderHint(QPainter::Antialiasing);
1889 p->translate(0.5, 0);
1899 case CE_ToolBoxTabLabel:
1900 if (
const QStyleOptionToolBox *tb = qstyleoption_cast<
const QStyleOptionToolBox *>(opt)) {
1901 bool enabled = tb->state & State_Enabled;
1902 bool selected = tb->state & State_Selected;
1903 int iconExtent = proxy()->pixelMetric(QStyle::PM_SmallIconSize, tb, widget);
1904 QPixmap pm = tb->icon.pixmap(QSize(iconExtent, iconExtent), QStyleHelper::getDpr(p),
1905 enabled ? QIcon::Normal : QIcon::Disabled);
1907 QRect cr = subElementRect(QStyle::SE_ToolBoxTabContents, tb, widget);
1912 tr.adjust(4, 0, -8, 0);
1914 int iw = pm.width() / pm.devicePixelRatio() + 4;
1915 ih = pm.height()/ pm.devicePixelRatio();
1916 ir = QRect(cr.left() + 4, cr.top(), iw + 2, ih);
1917 tr = QRect(ir.right(), cr.top(), cr.width() - ir.right() - 4, cr.height());
1920 if (selected && proxy()->styleHint(QStyle::SH_ToolBox_SelectedPageTitleBold, tb, widget)) {
1926 QString txt = tb->fontMetrics.elidedText(tb->text, Qt::ElideRight, tr.width());
1929 p->drawPixmap(ir.left(), (tb->rect.height() - ih) / 2, pm);
1931 int alignment = Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic;
1932 if (!proxy()->styleHint(QStyle::SH_UnderlineShortcut, tb, widget))
1933 alignment |= Qt::TextHideMnemonic;
1934 proxy()->drawItemText(p, tr, alignment, tb->palette, enabled, txt, QPalette::ButtonText);
1936 if (!txt.isEmpty() && opt->state & State_HasFocus) {
1937 QStyleOptionFocusRect opt;
1939 opt.palette = tb->palette;
1940 opt.state = QStyle::State_None;
1941 proxy()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, p, widget);
1945 case CE_TabBarTabLabel:
1946 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
1947 QRect tr = tab->rect;
1948 bool verticalTabs = tab->shape == QTabBar::RoundedEast
1949 || tab->shape == QTabBar::RoundedWest
1950 || tab->shape == QTabBar::TriangularEast
1951 || tab->shape == QTabBar::TriangularWest;
1953 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;
1954 if (!proxy()->styleHint(SH_UnderlineShortcut, opt, widget))
1955 alignment |= Qt::TextHideMnemonic;
1957 QPainterStateGuard psg(p, QPainterStateGuard::InitialState::NoSave);
1960 int newX, newY, newRot;
1961 if (tab->shape == QTabBar::RoundedEast || tab->shape == QTabBar::TriangularEast) {
1962 newX = tr.width() + tr.x();
1967 newY = tr.y() + tr.height();
1970 QTransform m = QTransform::fromTranslate(newX, newY);
1972 p->setTransform(m,
true);
1975 d->tabLayout(tab, widget, &tr, &iconRect);
1978 if (tab->position != QStyleOptionTab::TabPosition::Moving)
1979 tr = proxy()->subElementRect(SE_TabBarTabText, opt, widget);
1981 if (!tab->icon.isNull()) {
1982 const auto mode = (tab->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled;
1983 const auto state = (tab->state & State_Selected) ? QIcon::On : QIcon::Off;
1984 const auto tabIcon =
1985 tab->icon.pixmap(tab->iconSize, QStyleHelper::getDpr(p), mode, state);
1986 p->drawPixmap(iconRect.x(), iconRect.y(), tabIcon);
1989 proxy()->drawItemText(p, tr, alignment, tab->palette, tab->state & State_Enabled, tab->text,
1990 widget ? widget->foregroundRole() : QPalette::WindowText);
1994 if (tab->state & State_HasFocus) {
1995 const int OFFSET = 1 + pixelMetric(PM_DefaultFrameWidth, opt, widget);
1998 x1 = tab->rect.left();
1999 x2 = tab->rect.right() - 1;
2001 QStyleOptionFocusRect fropt;
2002 fropt.QStyleOption::operator=(*tab);
2003 fropt.rect.setRect(x1 + 1 + OFFSET, tab->rect.y() + OFFSET,
2004 x2 - x1 - 2*OFFSET, tab->rect.height() - 2*OFFSET);
2005 drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
2010#if QT_CONFIG(sizegrip)
2012 QPainterStateGuard psg(p);
2014 opt->rect.getRect(&x, &y, &w, &h);
2016 int sw = qMin(h, w);
2018 p->translate(0, h - w);
2020 p->translate(w - h, 0);
2027 if (
const QStyleOptionSizeGrip *sgOpt = qstyleoption_cast<
const QStyleOptionSizeGrip *>(opt))
2028 corner = sgOpt->corner;
2029 else if (opt->direction == Qt::RightToLeft)
2030 corner = Qt::BottomLeftCorner;
2032 corner = Qt::BottomRightCorner;
2034 if (corner == Qt::BottomLeftCorner) {
2036 for (
int i = 0; i < 4; ++i) {
2037 p->setPen(opt->palette.light().color());
2038 p->drawLine(x, sy - 1 , sx + 1, sw);
2039 p->setPen(opt->palette.dark().color());
2040 p->drawLine(x, sy, sx, sw);
2041 p->setPen(opt->palette.dark().color());
2042 p->drawLine(x, sy + 1, sx - 1, sw);
2046 }
else if (corner == Qt::BottomRightCorner) {
2047 for (
int i = 0; i < 4; ++i) {
2048 p->setPen(opt->palette.light().color());
2049 p->drawLine(sx - 1, sw, sw, sy - 1);
2050 p->setPen(opt->palette.dark().color());
2051 p->drawLine(sx, sw, sw, sy);
2052 p->setPen(opt->palette.dark().color());
2053 p->drawLine(sx + 1, sw, sw, sy + 1);
2057 }
else if (corner == Qt::TopRightCorner) {
2059 for (
int i = 0; i < 4; ++i) {
2060 p->setPen(opt->palette.light().color());
2061 p->drawLine(sx - 1, y, sw, sy + 1);
2062 p->setPen(opt->palette.dark().color());
2063 p->drawLine(sx, y, sw, sy);
2064 p->setPen(opt->palette.dark().color());
2065 p->drawLine(sx + 1, y, sw, sy - 1);
2069 }
else if (corner == Qt::TopLeftCorner) {
2070 for (
int i = 0; i < 4; ++i) {
2071 p->setPen(opt->palette.light().color());
2072 p->drawLine(x, sy - 1, sx - 1, y);
2073 p->setPen(opt->palette.dark().color());
2074 p->drawLine(x, sy, sx, y);
2075 p->setPen(opt->palette.dark().color());
2076 p->drawLine(x, sy + 1, sx + 1, y);
2083#if QT_CONFIG(rubberband)
2084 case CE_RubberBand: {
2085 if (
const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<
const QStyleOptionRubberBand *>(opt)) {
2086 QPixmap tiledPixmap(16, 16);
2087 QPainter pixmapPainter(&tiledPixmap);
2088 pixmapPainter.setPen(Qt::NoPen);
2089 pixmapPainter.setBrush(Qt::Dense4Pattern);
2090 pixmapPainter.setBackground(QBrush(opt->palette.base()));
2091 pixmapPainter.setBackgroundMode(Qt::OpaqueMode);
2092 pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height());
2093 pixmapPainter.end();
2095 tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage());
2097 QPainterStateGuard psg(p);
2098 QRect r = opt->rect;
2099 QStyleHintReturnMask mask;
2100 if (proxy()->styleHint(QStyle::SH_RubberBand_Mask, opt, widget, &mask))
2101 p->setClipRegion(mask.region);
2102 p->drawTiledPixmap(r.x(), r.y(), r.width(), r.height(), tiledPixmap);
2103 p->setPen(opt->palette.color(QPalette::Active, QPalette::WindowText));
2104 p->setBrush(Qt::NoBrush);
2105 p->drawRect(r.adjusted(0, 0, -1, -1));
2106 if (rbOpt->shape == QRubberBand::Rectangle)
2107 p->drawRect(r.adjusted(3, 3, -4, -4));
2111#if QT_CONFIG(dockwidget)
2112 case CE_DockWidgetTitle:
2113 if (
const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<
const QStyleOptionDockWidget *>(opt)) {
2114 QRect r = dwOpt->rect.adjusted(0, 0, -1, -1);
2115 if (dwOpt->movable) {
2116 p->setPen(dwOpt->palette.color(QPalette::Dark));
2120 if (!dwOpt->title.isEmpty()) {
2121 const bool verticalTitleBar = dwOpt->verticalTitleBar;
2123 QPainterStateGuard psg(p, QPainterStateGuard::InitialState::NoSave);
2124 if (verticalTitleBar) {
2128 p->translate(r.left(), r.top() + r.width());
2130 p->translate(-r.left(), -r.top());
2133 const int indent = p->fontMetrics().descent();
2134 proxy()->drawItemText(p, r.adjusted(indent + 1, 1, -indent - 1, -1),
2135 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextHideMnemonic, dwOpt->palette,
2136 dwOpt->state & State_Enabled, dwOpt->title,
2137 QPalette::WindowText);
2143 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
2144 QPainterStateGuard psg(p);
2145 p->setClipRect(opt->rect);
2146 proxy()->drawControl(CE_HeaderSection, header, p, widget);
2148 QStyleOptionHeaderV2 subopt;
2149 QStyleOptionHeader &v1Copy = subopt;
2150 if (
auto v2 = qstyleoption_cast<
const QStyleOptionHeaderV2 *>(opt))
2154 subopt.rect = subElementRect(SE_HeaderLabel, header, widget);
2155 if (subopt.rect.isValid())
2156 proxy()->drawControl(CE_HeaderLabel, &subopt, p, widget);
2157 if (header->sortIndicator != QStyleOptionHeader::None) {
2158 subopt.rect = subElementRect(SE_HeaderArrow, opt, widget);
2159 proxy()->drawPrimitive(PE_IndicatorHeaderArrow, &subopt, p, widget);
2164 p->fillRect(opt->rect, opt->palette.windowText());
2166 case CE_HeaderSection:
2167 qDrawShadePanel(p, opt->rect, opt->palette,
2168 opt->state & State_Sunken, 1,
2169 &opt->palette.brush(QPalette::Button));
2171 case CE_HeaderEmptyArea:
2172 p->fillRect(opt->rect, opt->palette.window());
2174#if QT_CONFIG(combobox)
2175 case CE_ComboBoxLabel:
2176 if (
const QStyleOptionComboBox *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
2177 QRect editRect = proxy()->subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget);
2178 QPainterStateGuard psg(p);
2179 p->setClipRect(editRect);
2180 if (!cb->currentIcon.isNull()) {
2181 QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal
2183 QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, QStyleHelper::getDpr(p), mode);
2184 QRect iconRect(editRect);
2185 iconRect.setWidth(cb->iconSize.width() + 4);
2186 iconRect = alignedRect(cb->direction,
2187 Qt::AlignLeft | Qt::AlignVCenter,
2188 iconRect.size(), editRect);
2190 p->fillRect(iconRect, opt->palette.brush(QPalette::Base));
2191 proxy()->drawItemPixmap(p, iconRect, Qt::AlignCenter, pixmap);
2193 if (cb->direction == Qt::RightToLeft)
2194 editRect.translate(-4 - cb->iconSize.width(), 0);
2196 editRect.translate(cb->iconSize.width() + 4, 0);
2198 if (!cb->currentText.isEmpty() && !cb->editable) {
2200 proxy()->drawItemText(p, editRect.adjusted(2, 0, -2, 0),
2201 visualAlignment(cb->direction, cb->textAlignment),
2202 cb->palette, cb->state & State_Enabled, cb->currentText);
2207#if QT_CONFIG(toolbar)
2209 if (
const QStyleOptionToolBar *toolBar = qstyleoption_cast<
const QStyleOptionToolBar *>(opt)) {
2211 QStyleOptionFrame frame;
2212 frame.QStyleOption::operator=(*toolBar);
2213 frame.lineWidth = toolBar->lineWidth;
2214 frame.midLineWidth = toolBar->midLineWidth;
2215 proxy()->drawPrimitive(PE_PanelToolBar, opt, p, widget);
2217 if (widget && qobject_cast<QToolBar *>(widget->parentWidget()))
2219 qDrawShadePanel(p, toolBar->rect, toolBar->palette,
false, toolBar->lineWidth,
2220 &toolBar->palette.brush(QPalette::Button));
2224 case CE_ColumnViewGrip: {
2226 QLinearGradient g(0, 0, opt->rect.width(), 0);
2227 g.setColorAt(0, opt->palette.color(QPalette::Active, QPalette::Mid));
2228 g.setColorAt(0.5, Qt::white);
2229 p->fillRect(QRect(0, 0, opt->rect.width(), opt->rect.height()), g);
2233 pen.setWidth(opt->rect.width()/20);
2234 pen.setColor(opt->palette.color(QPalette::Active, QPalette::Dark));
2237 int line1starting = opt->rect.width()*8 / 20;
2238 int line2starting = opt->rect.width()*13 / 20;
2239 int top = opt->rect.height()*20/75;
2240 int bottom = opt->rect.height() - 1 - top;
2241 p->drawLine(line1starting, top, line1starting, bottom);
2242 p->drawLine(line2starting, top, line2starting, bottom);
2246#if QT_CONFIG(itemviews)
2247 case CE_ItemViewItem:
2248 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
2249 QPainterStateGuard psg(p);
2251 const QRegion clipRegion = p->hasClipping() ? (p->clipRegion() & opt->rect) : opt->rect;
2252 p->setClipRegion(clipRegion);
2254 QRect checkRect = proxy()->subElementRect(SE_ItemViewItemCheckIndicator, vopt, widget);
2255 QRect iconRect = proxy()->subElementRect(SE_ItemViewItemDecoration, vopt, widget);
2256 QRect textRect = proxy()->subElementRect(SE_ItemViewItemText, vopt, widget);
2259 proxy()->drawPrimitive(PE_PanelItemViewItem, opt, p, widget);
2262 if (vopt->features & QStyleOptionViewItem::HasCheckIndicator) {
2263 QStyleOptionViewItem option(*vopt);
2264 option.rect = checkRect;
2265 option.state = option.state & ~QStyle::State_HasFocus;
2267 switch (vopt->checkState) {
2269 option.state |= QStyle::State_Off;
2271 case Qt::PartiallyChecked:
2272 option.state |= QStyle::State_NoChange;
2275 option.state |= QStyle::State_On;
2278 proxy()->drawPrimitive(QStyle::PE_IndicatorItemViewItemCheck, &option, p, widget);
2282 QIcon::Mode mode = QIcon::Normal;
2283 if (!(vopt->state & QStyle::State_Enabled))
2284 mode = QIcon::Disabled;
2285 else if (vopt->state & QStyle::State_Selected)
2286 mode = QIcon::Selected;
2287 QIcon::State state = vopt->state & QStyle::State_Open ? QIcon::On : QIcon::Off;
2288 vopt->icon.paint(p, iconRect, vopt->decorationAlignment, mode, state);
2291 if (!vopt->text.isEmpty()) {
2292 QPalette::ColorGroup cg = vopt->state & QStyle::State_Enabled
2293 ? QPalette::Normal : QPalette::Disabled;
2294 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))
2295 cg = QPalette::Inactive;
2297 if (vopt->state & QStyle::State_Selected) {
2298 p->setPen(vopt->palette.color(cg, QPalette::HighlightedText));
2300 p->setPen(vopt->palette.color(cg, QPalette::Text));
2302 d->viewItemDrawText(p, vopt, textRect);
2306 if (vopt->state & QStyle::State_HasFocus) {
2307 QStyleOptionFocusRect o;
2308 o.QStyleOption::operator=(*vopt);
2309 o.rect = proxy()->subElementRect(SE_ItemViewItemFocusRect, vopt, widget);
2310 o.state |= QStyle::State_KeyboardFocusChange;
2311 o.state |= QStyle::State_Item;
2312 QPalette::ColorGroup cg = (vopt->state & QStyle::State_Enabled)
2313 ? QPalette::Normal : QPalette::Disabled;
2314 o.backgroundColor = vopt->palette.color(cg, (vopt->state & QStyle::State_Selected)
2315 ? QPalette::Highlight : QPalette::Window);
2316 proxy()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, p, widget);
2323 case CE_ShapedFrame:
2324 if (
const QStyleOptionFrame *f = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
2325 int frameShape = f->frameShape;
2326 int frameShadow = QFrame::Plain;
2327 if (f->state & QStyle::State_Sunken) {
2328 frameShadow = QFrame::Sunken;
2329 }
else if (f->state & QStyle::State_Raised) {
2330 frameShadow = QFrame::Raised;
2333 int lw = f->lineWidth;
2334 int mlw = f->midLineWidth;
2335 QPalette::ColorRole foregroundRole = QPalette::WindowText;
2337 foregroundRole = widget->foregroundRole();
2339 switch (frameShape) {
2341 if (frameShadow == QFrame::Plain) {
2342 qDrawPlainRect(p, f->rect, f->palette.color(foregroundRole), lw);
2344 qDrawShadeRect(p, f->rect, f->palette, frameShadow == QFrame::Sunken, lw, mlw);
2347 case QFrame::StyledPanel:
2351 widget->style()->drawPrimitive(QStyle::PE_Frame, opt, p, widget);
2353 proxy()->drawPrimitive(QStyle::PE_Frame, opt, p, widget);
2357 if (frameShadow == QFrame::Plain) {
2358 qDrawPlainRect(p, f->rect, f->palette.color(foregroundRole), lw);
2360 qDrawShadePanel(p, f->rect, f->palette, frameShadow == QFrame::Sunken, lw);
2363 case QFrame::WinPanel:
2364 if (frameShadow == QFrame::Plain) {
2365 qDrawPlainRect(p, f->rect, f->palette.color(foregroundRole), lw);
2367 qDrawWinPanel(p, f->rect, f->palette, frameShadow == QFrame::Sunken);
2371 case QFrame::VLine: {
2373 if (frameShape == QFrame::HLine) {
2374 p1 = QPoint(opt->rect.x(), opt->rect.y() + opt->rect.height() / 2);
2375 p2 = QPoint(opt->rect.x() + opt->rect.width(), p1.y());
2377 p1 = QPoint(opt->rect.x() + opt->rect.width() / 2, opt->rect.y());
2378 p2 = QPoint(p1.x(), p1.y() + opt->rect.height());
2380 if (frameShadow == QFrame::Plain) {
2381 QPen oldPen = p->pen();
2382 p->setPen(QPen(opt->palette.brush(foregroundRole), lw));
2383 p->drawLine(p1, p2);
2386 qDrawShadeLine(p, p1, p2, f->palette, frameShadow == QFrame::Sunken, lw, mlw);
2397#if !QT_CONFIG(tabbar) && !QT_CONFIG(itemviews)
2405QRect QCommonStyle::subElementRect(SubElement sr,
const QStyleOption *opt,
2406 const QWidget *widget)
const
2408 Q_D(
const QCommonStyle);
2411 case SE_PushButtonContents:
2412 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
2414 dx1 = proxy()->pixelMetric(PM_DefaultFrameWidth, btn, widget);
2415 if (btn->features & QStyleOptionButton::AutoDefaultButton)
2416 dx1 += proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
2418 r.setRect(opt->rect.x() + dx1, opt->rect.y() + dx1, opt->rect.width() - dx2,
2419 opt->rect.height() - dx2);
2420 r = visualRect(opt->direction, opt->rect, r);
2423 case SE_PushButtonFocusRect:
2424 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
2425 int dbw1 = 0, dbw2 = 0;
2426 if (btn->features & QStyleOptionButton::AutoDefaultButton){
2427 dbw1 = proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
2431 int dfw1 = proxy()->pixelMetric(PM_DefaultFrameWidth, btn, widget) + 1,
2434 r.setRect(btn->rect.x() + dfw1 + dbw1, btn->rect.y() + dfw1 + dbw1,
2435 btn->rect.width() - dfw2 - dbw2, btn->rect.height()- dfw2 - dbw2);
2436 r = visualRect(opt->direction, opt->rect, r);
2439 case SE_PushButtonBevel:
2442 r = visualRect(opt->direction, opt->rect, r);
2445 case SE_CheckBoxIndicator:
2447 int h = proxy()->pixelMetric(PM_IndicatorHeight, opt, widget);
2448 r.setRect(opt->rect.x(), opt->rect.y() + ((opt->rect.height() - h) / 2),
2449 proxy()->pixelMetric(PM_IndicatorWidth, opt, widget), h);
2450 r = visualRect(opt->direction, opt->rect, r);
2454 case SE_CheckBoxContents:
2457 QRect ir = visualRect(opt->direction, opt->rect,
2458 subElementRect(SE_CheckBoxIndicator, opt, widget));
2459 int spacing = proxy()->pixelMetric(PM_CheckBoxLabelSpacing, opt, widget);
2460 r.setRect(ir.right() + spacing, opt->rect.y(), opt->rect.width() - ir.width() - spacing,
2461 opt->rect.height());
2462 r = visualRect(opt->direction, opt->rect, r);
2466 case SE_CheckBoxFocusRect:
2467 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
2468 if (btn->icon.isNull() && btn->text.isEmpty()) {
2469 r = subElementRect(SE_CheckBoxIndicator, opt, widget);
2470 r.adjust(1, 1, -1, -1);
2474 QRect cr = visualRect(btn->direction, btn->rect,
2475 subElementRect(SE_CheckBoxContents, btn, widget));
2477 QRect iconRect, textRect;
2478 if (!btn->text.isEmpty()) {
2479 textRect = itemTextRect(opt->fontMetrics, cr, Qt::AlignAbsolute | Qt::AlignLeft
2480 | Qt::AlignVCenter | Qt::TextShowMnemonic,
2481 btn->state & State_Enabled, btn->text);
2483 if (!btn->icon.isNull()) {
2484 iconRect = itemPixmapRect(cr, Qt::AlignAbsolute | Qt::AlignLeft | Qt::AlignVCenter
2485 | Qt::TextShowMnemonic,
2486 btn->icon.pixmap(btn->iconSize, QStyleHelper::getDpr(widget), QIcon::Normal));
2487 if (!textRect.isEmpty())
2488 textRect.translate(iconRect.right() + 4, 0);
2490 r = iconRect | textRect;
2491 r.adjust(-3, -2, 3, 2);
2492 r = r.intersected(btn->rect);
2493 r = visualRect(btn->direction, btn->rect, r);
2497 case SE_RadioButtonIndicator:
2499 int h = proxy()->pixelMetric(PM_ExclusiveIndicatorHeight, opt, widget);
2500 r.setRect(opt->rect.x(), opt->rect.y() + ((opt->rect.height() - h) / 2),
2501 proxy()->pixelMetric(PM_ExclusiveIndicatorWidth, opt, widget), h);
2502 r = visualRect(opt->direction, opt->rect, r);
2506 case SE_RadioButtonContents:
2508 QRect ir = visualRect(opt->direction, opt->rect,
2509 subElementRect(SE_RadioButtonIndicator, opt, widget));
2510 int spacing = proxy()->pixelMetric(PM_RadioButtonLabelSpacing, opt, widget);
2511 r.setRect(ir.right() + spacing, opt->rect.y(), opt->rect.width() - ir.width() - spacing,
2512 opt->rect.height());
2513 r = visualRect(opt->direction, opt->rect, r);
2517 case SE_RadioButtonFocusRect:
2518 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
2519 if (btn->icon.isNull() && btn->text.isEmpty()) {
2520 r = subElementRect(SE_RadioButtonIndicator, opt, widget);
2521 r.adjust(1, 1, -1, -1);
2524 QRect cr = visualRect(btn->direction, btn->rect,
2525 subElementRect(SE_RadioButtonContents, opt, widget));
2527 QRect iconRect, textRect;
2528 if (!btn->text.isEmpty()){
2529 textRect = itemTextRect(opt->fontMetrics, cr, Qt::AlignAbsolute | Qt::AlignLeft | Qt::AlignVCenter
2530 | Qt::TextShowMnemonic, btn->state & State_Enabled, btn->text);
2532 if (!btn->icon.isNull()) {
2533 iconRect = itemPixmapRect(cr, Qt::AlignAbsolute | Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic,
2534 btn->icon.pixmap(btn->iconSize, QStyleHelper::getDpr(widget), QIcon::Normal));
2535 if (!textRect.isEmpty())
2536 textRect.translate(iconRect.right() + 4, 0);
2538 r = iconRect | textRect;
2539 r.adjust(-3, -2, 3, 2);
2540 r = r.intersected(btn->rect);
2541 r = visualRect(btn->direction, btn->rect, r);
2544#if QT_CONFIG(slider)
2545 case SE_SliderFocusRect:
2546 if (
const QStyleOptionSlider *slider = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
2547 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider, widget);
2548 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
2549 if (slider->orientation == Qt::Horizontal)
2550 r.setRect(0, tickOffset - 1, slider->rect.width(), thickness + 2);
2552 r.setRect(tickOffset - 1, 0, thickness + 2, slider->rect.height());
2553 r = r.intersected(slider->rect);
2554 r = visualRect(opt->direction, opt->rect, r);
2558#if QT_CONFIG(progressbar)
2559 case SE_ProgressBarGroove:
2560 case SE_ProgressBarContents:
2561 case SE_ProgressBarLabel:
2562 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
2564 const bool vertical = !(pb->state & QStyle::State_Horizontal);
2566 if (pb->textVisible)
2567 textw = qMax(pb->fontMetrics.horizontalAdvance(pb->text), pb->fontMetrics.horizontalAdvance(
"100%"_L1)) + 6;
2570 if ((pb->textAlignment & Qt::AlignCenter) == 0) {
2571 if (sr != SE_ProgressBarLabel)
2572 r.setCoords(pb->rect.left(), pb->rect.top(),
2573 pb->rect.right() - textw, pb->rect.bottom());
2575 r.setCoords(pb->rect.right() - textw, pb->rect.top(),
2576 pb->rect.right(), pb->rect.bottom());
2580 r = visualRect(pb->direction, pb->rect, r);
2584#if QT_CONFIG(combobox)
2585 case SE_ComboBoxFocusRect:
2586 if (
const QStyleOptionComboBox *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
2587 int margin = cb->frame ? 3 : 0;
2588 r.setRect(opt->rect.left() + margin, opt->rect.top() + margin,
2589 opt->rect.width() - 2*margin - 16, opt->rect.height() - 2*margin);
2590 r = visualRect(opt->direction, opt->rect, r);
2594#if QT_CONFIG(toolbox)
2595 case SE_ToolBoxTabContents:
2597 r.adjust(0, 0, -30, 0);
2600 case SE_HeaderLabel: {
2601 const int margin = proxy()->pixelMetric(PM_HeaderMargin, opt, widget);
2602 r = opt->rect.marginsRemoved({ margin, margin, margin, margin });
2604 if (
const auto *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
2606 if (header->sortIndicator != QStyleOptionHeader::None) {
2607 const int hdrSize = proxy()->pixelMetric(PM_HeaderMarkSize, opt, widget);
2608 if (opt->state & State_Horizontal)
2609 r.setWidth(r.width() - hdrSize);
2611 r.setHeight(r.height() - hdrSize);
2614 r = visualRect(opt->direction, opt->rect, r);
2617 case SE_HeaderArrow: {
2618 const auto &rect = opt->rect;
2619 const int margin = proxy()->pixelMetric(PM_HeaderMargin, opt, widget);
2620 const int arrowSize = proxy()->pixelMetric(PM_HeaderMarkSize, opt, widget);
2622 if (opt->state & State_Horizontal) {
2623 const int yCenter = rect.center().y();
2624 r.setRect(rect.right() - margin * 2 - arrowSize, yCenter - arrowSize / 2,
2625 arrowSize, arrowSize);
2627 const int xCenter = rect.center().x();
2628 r.setRect(xCenter - arrowSize / 2, rect.bottom() - margin * 2 - arrowSize,
2629 arrowSize, arrowSize);
2631 r = visualRect(opt->direction, opt->rect, r);
2635 case SE_RadioButtonClickRect:
2636 r = subElementRect(SE_RadioButtonFocusRect, opt, widget);
2637 r |= subElementRect(SE_RadioButtonIndicator, opt, widget);
2639 case SE_CheckBoxClickRect:
2640 r = subElementRect(SE_CheckBoxFocusRect, opt, widget);
2641 r |= subElementRect(SE_CheckBoxIndicator, opt, widget);
2643#if QT_CONFIG(tabwidget)
2644 case SE_TabWidgetTabBar:
2645 if (
const QStyleOptionTabWidgetFrame *twf
2646 = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
2647 r.setSize(twf->tabBarSize);
2648 const uint alingMask = Qt::AlignLeft | Qt::AlignRight | Qt::AlignHCenter;
2649 switch (twf->shape) {
2650 case QTabBar::RoundedNorth:
2651 case QTabBar::TriangularNorth:
2654 r.setWidth(qMin(r.width(), twf->rect.width()
2655 - twf->leftCornerWidgetSize.width()
2656 - twf->rightCornerWidgetSize.width()));
2657 switch (proxy()->styleHint(SH_TabBar_Alignment, twf, widget) & alingMask) {
2660 r.moveTopLeft(QPoint(twf->leftCornerWidgetSize.width(), 0));
2662 case Qt::AlignHCenter:
2663 r.moveTopLeft(QPoint(twf->rect.center().x() - qRound(r.width() / 2.0f)
2664 + (twf->leftCornerWidgetSize.width() / 2)
2665 - (twf->rightCornerWidgetSize.width() / 2), 0));
2667 case Qt::AlignRight:
2668 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width()
2669 - twf->rightCornerWidgetSize.width(), 0));
2672 r = visualRect(twf->direction, twf->rect, r);
2674 case QTabBar::RoundedSouth:
2675 case QTabBar::TriangularSouth:
2676 r.setWidth(qMin(r.width(), twf->rect.width()
2677 - twf->leftCornerWidgetSize.width()
2678 - twf->rightCornerWidgetSize.width()));
2679 switch (proxy()->styleHint(SH_TabBar_Alignment, twf, widget) & alingMask) {
2682 r.moveTopLeft(QPoint(twf->leftCornerWidgetSize.width(),
2683 twf->rect.height() - twf->tabBarSize.height()));
2685 case Qt::AlignHCenter:
2686 r.moveTopLeft(QPoint(twf->rect.center().x() - qRound(r.width() / 2.0f)
2687 + (twf->leftCornerWidgetSize.width() / 2)
2688 - (twf->rightCornerWidgetSize.width() / 2),
2689 twf->rect.height() - twf->tabBarSize.height()));
2691 case Qt::AlignRight:
2692 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width()
2693 - twf->rightCornerWidgetSize.width(),
2694 twf->rect.height() - twf->tabBarSize.height()));
2697 r = visualRect(twf->direction, twf->rect, r);
2699 case QTabBar::RoundedEast:
2700 case QTabBar::TriangularEast:
2701 r.setHeight(qMin(r.height(), twf->rect.height()
2702 - twf->leftCornerWidgetSize.height()
2703 - twf->rightCornerWidgetSize.height()));
2704 switch (proxy()->styleHint(SH_TabBar_Alignment, twf, widget) & alingMask) {
2707 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width(),
2708 twf->leftCornerWidgetSize.height()));
2710 case Qt::AlignHCenter:
2711 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width(),
2712 twf->rect.center().y() - r.height() / 2));
2714 case Qt::AlignRight:
2715 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width(),
2716 twf->rect.height() - twf->tabBarSize.height()
2717 - twf->rightCornerWidgetSize.height()));
2721 case QTabBar::RoundedWest:
2722 case QTabBar::TriangularWest:
2723 r.setHeight(qMin(r.height(), twf->rect.height()
2724 - twf->leftCornerWidgetSize.height()
2725 - twf->rightCornerWidgetSize.height()));
2726 switch (proxy()->styleHint(SH_TabBar_Alignment, twf, widget) & alingMask) {
2729 r.moveTopLeft(QPoint(0, twf->leftCornerWidgetSize.height()));
2731 case Qt::AlignHCenter:
2732 r.moveTopLeft(QPoint(0, twf->rect.center().y() - r.height() / 2));
2734 case Qt::AlignRight:
2735 r.moveTopLeft(QPoint(0, twf->rect.height() - twf->tabBarSize.height()
2736 - twf->rightCornerWidgetSize.height()));
2743 case SE_TabWidgetTabPane:
2744 case SE_TabWidgetTabContents:
2745 if (
const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
2746 QStyleOptionTab tabopt;
2747 tabopt.shape = twf->shape;
2748 int overlap = proxy()->pixelMetric(PM_TabBarBaseOverlap, &tabopt, widget);
2749 if (twf->lineWidth == 0)
2751 switch (twf->shape) {
2752 case QTabBar::RoundedNorth:
2753 case QTabBar::TriangularNorth:
2754 r = QRect(QPoint(0,qMax(twf->tabBarSize.height() - overlap, 0)),
2755 QSize(twf->rect.width(), qMin(twf->rect.height() - twf->tabBarSize.height() + overlap, twf->rect.height())));
2757 case QTabBar::RoundedSouth:
2758 case QTabBar::TriangularSouth:
2759 r = QRect(QPoint(0,0), QSize(twf->rect.width(), qMin(twf->rect.height() - twf->tabBarSize.height() + overlap, twf->rect.height())));
2761 case QTabBar::RoundedEast:
2762 case QTabBar::TriangularEast:
2763 r = QRect(QPoint(0, 0), QSize(qMin(twf->rect.width() - twf->tabBarSize.width() + overlap, twf->rect.width()), twf->rect.height()));
2765 case QTabBar::RoundedWest:
2766 case QTabBar::TriangularWest:
2767 r = QRect(QPoint(qMax(twf->tabBarSize.width() - overlap, 0), 0),
2768 QSize(qMin(twf->rect.width() - twf->tabBarSize.width() + overlap, twf->rect.width()), twf->rect.height()));
2771 if (sr == SE_TabWidgetTabContents && twf->lineWidth > 0)
2772 r.adjust(2, 2, -2, -2);
2775 case SE_TabWidgetLeftCorner:
2776 if (
const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
2777 QRect paneRect = subElementRect(SE_TabWidgetTabPane, twf, widget);
2778 switch (twf->shape) {
2779 case QTabBar::RoundedNorth:
2780 case QTabBar::TriangularNorth:
2781 r = QRect(QPoint(paneRect.x(), paneRect.y() - twf->leftCornerWidgetSize.height()),
2782 twf->leftCornerWidgetSize);
2784 case QTabBar::RoundedSouth:
2785 case QTabBar::TriangularSouth:
2786 r = QRect(QPoint(paneRect.x(), paneRect.height()), twf->leftCornerWidgetSize);
2791 r = visualRect(twf->direction, twf->rect, r);
2794 case SE_TabWidgetRightCorner:
2795 if (
const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
2796 QRect paneRect = subElementRect(SE_TabWidgetTabPane, twf, widget);
2797 switch (twf->shape) {
2798 case QTabBar::RoundedNorth:
2799 case QTabBar::TriangularNorth:
2800 r = QRect(QPoint(paneRect.width() - twf->rightCornerWidgetSize.width(),
2801 paneRect.y() - twf->rightCornerWidgetSize.height()),
2802 twf->rightCornerWidgetSize);
2804 case QTabBar::RoundedSouth:
2805 case QTabBar::TriangularSouth:
2806 r = QRect(QPoint(paneRect.width() - twf->rightCornerWidgetSize.width(),
2807 paneRect.height()), twf->rightCornerWidgetSize);
2812 r = visualRect(twf->direction, twf->rect, r);
2815 case SE_TabBarTabText:
2816 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
2817 QRect dummyIconRect;
2818 d->tabLayout(tab, widget, &r, &dummyIconRect);
2821 case SE_TabBarTabLeftButton:
2822 case SE_TabBarTabRightButton:
2823 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
2824 bool selected = tab->state & State_Selected;
2825 int verticalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab, widget);
2826 int horizontalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab, widget);
2827 int hpadding = proxy()->pixelMetric(QStyle::PM_TabBarTabHSpace, opt, widget) / 2;
2829 bool verticalTabs = tab->shape == QTabBar::RoundedEast
2830 || tab->shape == QTabBar::RoundedWest
2831 || tab->shape == QTabBar::TriangularEast
2832 || tab->shape == QTabBar::TriangularWest;
2834 QRect tr = tab->rect;
2835 if (tab->shape == QTabBar::RoundedSouth || tab->shape == QTabBar::TriangularSouth)
2836 verticalShift = -verticalShift;
2838 qSwap(horizontalShift, verticalShift);
2839 horizontalShift *= -1;
2840 verticalShift *= -1;
2842 if (tab->shape == QTabBar::RoundedWest || tab->shape == QTabBar::TriangularWest)
2843 horizontalShift = -horizontalShift;
2845 tr.adjust(0, 0, horizontalShift, verticalShift);
2848 tr.setBottom(tr.bottom() - verticalShift);
2849 tr.setRight(tr.right() - horizontalShift);
2852 QSize size = (sr == SE_TabBarTabLeftButton) ? tab->leftButtonSize : tab->rightButtonSize;
2853 int w = size.width();
2854 int h = size.height();
2856 bool atTheTop =
true;
2857 switch (tab->shape) {
2858 case QTabBar::RoundedWest:
2859 case QTabBar::TriangularWest:
2860 atTheTop = (sr == SE_TabBarTabLeftButton);
2862 case QTabBar::RoundedEast:
2863 case QTabBar::TriangularEast:
2864 atTheTop = (sr == SE_TabBarTabRightButton);
2867 const int midHeight =
2868 tr.y() +
static_cast<
int>(qCeil(
float(tr.height() - h) / 2));
2869 if (sr == SE_TabBarTabLeftButton)
2870 r = QRect(tab->rect.x() + hpadding, midHeight, w, h);
2872 r = QRect(tab->rect.right() - w - hpadding, midHeight, w, h);
2873 r = visualRect(tab->direction, tab->rect, r);
2878 const int midWidth = tr.x() + ((tr.width() - w) / 2);
2880 r = QRect(midWidth, tr.y() + tab->rect.height() - hpadding - h, w, h);
2882 r = QRect(midWidth, tr.y() + hpadding, w, h);
2888#if QT_CONFIG(tabbar)
2889 case SE_TabBarTearIndicator:
2890 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
2891 switch (tab->shape) {
2892 case QTabBar::RoundedNorth:
2893 case QTabBar::TriangularNorth:
2894 case QTabBar::RoundedSouth:
2895 case QTabBar::TriangularSouth:
2896 r.setRect(tab->rect.left(), tab->rect.top(), 8, opt->rect.height());
2898 case QTabBar::RoundedWest:
2899 case QTabBar::TriangularWest:
2900 case QTabBar::RoundedEast:
2901 case QTabBar::TriangularEast:
2902 r.setRect(tab->rect.left(), tab->rect.top(), opt->rect.width(), 8);
2907 r = visualRect(opt->direction, opt->rect, r);
2910 case SE_TabBarScrollLeftButton: {
2911 const bool vertical = opt->rect.width() < opt->rect.height();
2912 const Qt::LayoutDirection ld = widget->layoutDirection();
2913 const int buttonWidth = proxy()->pixelMetric(QStyle::PM_TabBarScrollButtonWidth,
nullptr, widget);
2914 const int buttonOverlap = proxy()->pixelMetric(QStyle::PM_TabBar_ScrollButtonOverlap,
nullptr, widget);
2916 r = vertical ? QRect(0, opt->rect.height() - (buttonWidth * 2) + buttonOverlap, opt->rect.width(), buttonWidth)
2917 : QStyle::visualRect(ld, opt->rect, QRect(opt->rect.width() - (buttonWidth * 2) + buttonOverlap, 0, buttonWidth, opt->rect.height()));
2919 case SE_TabBarScrollRightButton: {
2920 const bool vertical = opt->rect.width() < opt->rect.height();
2921 const Qt::LayoutDirection ld = widget->layoutDirection();
2922 const int buttonWidth = proxy()->pixelMetric(QStyle::PM_TabBarScrollButtonWidth,
nullptr, widget);
2924 r = vertical ? QRect(0, opt->rect.height() - buttonWidth, opt->rect.width(), buttonWidth)
2925 : QStyle::visualRect(ld, opt->rect, QRect(opt->rect.width() - buttonWidth, 0, buttonWidth, opt->rect.height()));
2928 case SE_TreeViewDisclosureItem:
2931 case SE_LineEditContents:
2932 if (
const QStyleOptionFrame *f = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
2933 r = f->rect.adjusted(f->lineWidth, f->lineWidth, -f->lineWidth, -f->lineWidth);
2934 r = visualRect(opt->direction, opt->rect, r);
2937 case SE_FrameContents:
2938 if (
const QStyleOptionFrame *f = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
2939 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, f, widget);
2940 r = opt->rect.adjusted(fw, fw, -fw, -fw);
2941 r = visualRect(opt->direction, opt->rect, r);
2944 case SE_ShapedFrameContents:
2945 if (
const QStyleOptionFrame *f = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
2946 int frameShape = f->frameShape;
2947 int frameShadow = QFrame::Plain;
2948 if (f->state & QStyle::State_Sunken) {
2949 frameShadow = QFrame::Sunken;
2950 }
else if (f->state & QStyle::State_Raised) {
2951 frameShadow = QFrame::Raised;
2956 switch (frameShape) {
2957 case QFrame::NoFrame:
2964 switch (frameShadow) {
2966 frameWidth = f->lineWidth;
2968 case QFrame::Raised:
2969 case QFrame::Sunken:
2970 frameWidth = (
short)(f->lineWidth*2 + f->midLineWidth);
2975 case QFrame::StyledPanel:
2979 return widget->style()->subElementRect(QStyle::SE_FrameContents, opt, widget);
2981 return subElementRect(QStyle::SE_FrameContents, opt, widget);
2983 case QFrame::WinPanel:
2988 switch (frameShadow) {
2990 case QFrame::Raised:
2991 case QFrame::Sunken:
2992 frameWidth = f->lineWidth;
2997 r = f->rect.adjusted(frameWidth, frameWidth, -frameWidth, -frameWidth);
3000#if QT_CONFIG(dockwidget)
3001 case SE_DockWidgetCloseButton:
3002 case SE_DockWidgetFloatButton:
3003 case SE_DockWidgetTitleBarText:
3004 case SE_DockWidgetIcon: {
3005 int iconSize = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
3006 int buttonMargin = proxy()->pixelMetric(PM_DockWidgetTitleBarButtonMargin, opt, widget);
3007 int margin = proxy()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, opt, widget);
3008 QRect rect = opt->rect;
3010 const QStyleOptionDockWidget *dwOpt
3011 = qstyleoption_cast<
const QStyleOptionDockWidget*>(opt);
3012 bool canClose = dwOpt ==
nullptr ?
true : dwOpt->closable;
3013 bool canFloat = dwOpt ==
nullptr ?
false : dwOpt->floatable;
3015 const bool verticalTitleBar = dwOpt && dwOpt->verticalTitleBar;
3020 if (verticalTitleBar)
3021 rect = rect.transposed();
3025 int right = rect.right();
3026 int left = rect.left();
3030 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarCloseButton,
3031 opt, widget).actualSize(QSize(iconSize, iconSize));
3032 sz += QSize(buttonMargin, buttonMargin);
3033 if (verticalTitleBar)
3034 sz = sz.transposed();
3035 closeRect = QRect(right - sz.width(),
3036 rect.center().y() - sz.height()/2,
3037 sz.width(), sz.height());
3038 right = closeRect.left() - 1;
3040 if (sr == SE_DockWidgetCloseButton) {
3047 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarNormalButton,
3048 opt, widget).actualSize(QSize(iconSize, iconSize));
3049 sz += QSize(buttonMargin, buttonMargin);
3050 if (verticalTitleBar)
3051 sz = sz.transposed();
3052 floatRect = QRect(right - sz.width(),
3053 rect.center().y() - sz.height()/2,
3054 sz.width(), sz.height());
3055 right = floatRect.left() - 1;
3057 if (sr == SE_DockWidgetFloatButton) {
3063 if (
const QDockWidget *dw = qobject_cast<
const QDockWidget*>(widget)) {
3065 if (dw->isFloating())
3066 icon = dw->windowIcon();
3068 && icon.cacheKey() != QApplication::windowIcon().cacheKey()) {
3069 QSize sz = icon.actualSize(QSize(r.height(), r.height()));
3070 if (verticalTitleBar)
3071 sz = sz.transposed();
3072 iconRect = QRect(left, rect.center().y() - sz.height()/2,
3073 sz.width(), sz.height());
3074 left = iconRect.right() + margin;
3077 if (sr == SE_DockWidgetIcon) {
3082 QRect textRect = QRect(left, rect.top(),
3083 right - left, rect.height());
3084 if (sr == SE_DockWidgetTitleBarText) {
3091 if (verticalTitleBar) {
3092 r = QRect(rect.left() + r.top() - rect.top(),
3093 rect.top() + rect.right() - r.right(),
3094 r.height(), r.width());
3096 r = visualRect(opt->direction, rect, r);
3101#if QT_CONFIG(itemviews)
3102 case SE_ItemViewItemCheckIndicator:
3103 if (!qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
3104 r = subElementRect(SE_CheckBoxIndicator, opt, widget);
3108 case SE_ItemViewItemDecoration:
3109 case SE_ItemViewItemText:
3110 case SE_ItemViewItemFocusRect:
3111 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
3112 if (!d->isViewItemCached(*vopt)) {
3113 d->viewItemLayout(vopt, &d->checkRect, &d->decorationRect, &d->displayRect,
false);
3114 if (d->cachedOption) {
3115 delete d->cachedOption;
3116 d->cachedOption =
nullptr;
3118 d->cachedOption =
new QStyleOptionViewItem(*vopt);
3120 if (sr == SE_ItemViewItemCheckIndicator)
3122 else if (sr == SE_ItemViewItemDecoration)
3123 r = d->decorationRect;
3124 else if (sr == SE_ItemViewItemText || sr == SE_ItemViewItemFocusRect)
3129#if QT_CONFIG(toolbar)
3130 case SE_ToolBarHandle:
3131 if (
const QStyleOptionToolBar *tbopt = qstyleoption_cast<
const QStyleOptionToolBar *>(opt)) {
3132 if (tbopt->features & QStyleOptionToolBar::Movable) {
3135 const QToolBar *tb = qobject_cast<
const QToolBar*>(widget);
3136 const QMargins margins = tb && tb->layout() ? tb->layout()->contentsMargins() : QMargins(2, 2, 2, 2);
3137 const int handleExtent = proxy()->pixelMetric(QStyle::PM_ToolBarHandleExtent, opt, tb);
3138 if (tbopt->state & QStyle::State_Horizontal) {
3139 r = QRect(margins.left(), margins.top(),
3141 tbopt->rect.height() - (margins.top() + margins.bottom()));
3142 r = QStyle::visualRect(tbopt->direction, tbopt->rect, r);
3144 r = QRect(margins.left(), margins.top(),
3145 tbopt->rect.width() - (margins.left() + margins.right()),
3156#if !QT_CONFIG(tabwidget) && !QT_CONFIG(itemviews)
3203void QCommonStyle::drawComplexControl(ComplexControl cc,
const QStyleOptionComplex *opt,
3204 QPainter *p,
const QWidget *widget)
const
3207#if QT_CONFIG(slider)
3209 if (
const QStyleOptionSlider *slider = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
3210 if (slider->subControls == SC_SliderTickmarks) {
3211 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider, widget);
3212 int ticks = slider->tickPosition;
3213 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
3214 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
3215 int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget);
3216 int interval = slider->tickInterval;
3217 if (interval <= 0) {
3218 interval = slider->singleStep;
3219 if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
3221 - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3223 interval = slider->pageStep;
3227 int fudge = len / 2;
3230 QPainterStateGuard psg(p);
3231 p->translate(slider->rect.x(), slider->rect.y());
3232 p->setPen(slider->palette.windowText().color());
3233 int v = slider->minimum;
3234 while (v <= slider->maximum + 1) {
3235 if (v == slider->maximum + 1 && interval == 1)
3237 const int v_ = qMin(v, slider->maximum);
3238 pos = QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3239 v_, available) + fudge;
3240 if (slider->orientation == Qt::Horizontal) {
3241 if (ticks & QSlider::TicksAbove)
3242 p->drawLine(pos, 0, pos, tickOffset - 2);
3243 if (ticks & QSlider::TicksBelow)
3244 p->drawLine(pos, tickOffset + thickness + 1, pos,
3245 slider->rect.height()-1);
3247 if (ticks & QSlider::TicksAbove)
3248 p->drawLine(0, pos, tickOffset - 2, pos);
3249 if (ticks & QSlider::TicksBelow)
3250 p->drawLine(tickOffset + thickness + 1, pos,
3251 slider->rect.width()-1, pos);
3254 int nextInterval = v + interval;
3255 if (nextInterval < v)
3263#if QT_CONFIG(scrollbar)
3265 if (
const QStyleOptionSlider *scrollbar = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
3267 QStyleOptionSlider newScrollbar = *scrollbar;
3268 State saveFlags = scrollbar->state;
3270 if (scrollbar->subControls & SC_ScrollBarSubLine) {
3271 newScrollbar.state = saveFlags;
3272 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarSubLine, widget);
3273 if (newScrollbar.rect.isValid()) {
3274 if (!(scrollbar->activeSubControls & SC_ScrollBarSubLine))
3275 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3276 proxy()->drawControl(CE_ScrollBarSubLine, &newScrollbar, p, widget);
3279 if (scrollbar->subControls & SC_ScrollBarAddLine) {
3280 newScrollbar.rect = scrollbar->rect;
3281 newScrollbar.state = saveFlags;
3282 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarAddLine, widget);
3283 if (newScrollbar.rect.isValid()) {
3284 if (!(scrollbar->activeSubControls & SC_ScrollBarAddLine))
3285 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3286 proxy()->drawControl(CE_ScrollBarAddLine, &newScrollbar, p, widget);
3289 if (scrollbar->subControls & SC_ScrollBarSubPage) {
3290 newScrollbar.rect = scrollbar->rect;
3291 newScrollbar.state = saveFlags;
3292 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarSubPage, widget);
3293 if (newScrollbar.rect.isValid()) {
3294 if (!(scrollbar->activeSubControls & SC_ScrollBarSubPage))
3295 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3296 proxy()->drawControl(CE_ScrollBarSubPage, &newScrollbar, p, widget);
3299 if (scrollbar->subControls & SC_ScrollBarAddPage) {
3300 newScrollbar.rect = scrollbar->rect;
3301 newScrollbar.state = saveFlags;
3302 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarAddPage, widget);
3303 if (newScrollbar.rect.isValid()) {
3304 if (!(scrollbar->activeSubControls & SC_ScrollBarAddPage))
3305 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3306 proxy()->drawControl(CE_ScrollBarAddPage, &newScrollbar, p, widget);
3309 if (scrollbar->subControls & SC_ScrollBarFirst) {
3310 newScrollbar.rect = scrollbar->rect;
3311 newScrollbar.state = saveFlags;
3312 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarFirst, widget);
3313 if (newScrollbar.rect.isValid()) {
3314 if (!(scrollbar->activeSubControls & SC_ScrollBarFirst))
3315 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3316 proxy()->drawControl(CE_ScrollBarFirst, &newScrollbar, p, widget);
3319 if (scrollbar->subControls & SC_ScrollBarLast) {
3320 newScrollbar.rect = scrollbar->rect;
3321 newScrollbar.state = saveFlags;
3322 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarLast, widget);
3323 if (newScrollbar.rect.isValid()) {
3324 if (!(scrollbar->activeSubControls & SC_ScrollBarLast))
3325 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3326 proxy()->drawControl(CE_ScrollBarLast, &newScrollbar, p, widget);
3329 if (scrollbar->subControls & SC_ScrollBarSlider) {
3330 newScrollbar.rect = scrollbar->rect;
3331 newScrollbar.state = saveFlags;
3332 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarSlider, widget);
3333 if (newScrollbar.rect.isValid()) {
3334 if (!(scrollbar->activeSubControls & SC_ScrollBarSlider))
3335 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3336 proxy()->drawControl(CE_ScrollBarSlider, &newScrollbar, p, widget);
3338 if (scrollbar->state & State_HasFocus) {
3339 QStyleOptionFocusRect fropt;
3340 fropt.QStyleOption::operator=(newScrollbar);
3341 fropt.rect.setRect(newScrollbar.rect.x() + 2, newScrollbar.rect.y() + 2,
3342 newScrollbar.rect.width() - 5,
3343 newScrollbar.rect.height() - 5);
3344 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
3351#if QT_CONFIG(spinbox)
3353 if (
const QStyleOptionSpinBox *sb = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
3354 QStyleOptionSpinBox copy = *sb;
3355 PrimitiveElement pe;
3357 if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
3358 QRect r = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxFrame, widget);
3359 qDrawWinPanel(p, r, sb->palette,
true);
3362 if (sb->subControls & SC_SpinBoxUp) {
3363 copy.subControls = SC_SpinBoxUp;
3364 QPalette pal2 = sb->palette;
3365 if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled)) {
3366 pal2.setCurrentColorGroup(QPalette::Disabled);
3367 copy.state &= ~State_Enabled;
3370 copy.palette = pal2;
3372 if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken)) {
3373 copy.state |= State_On;
3374 copy.state |= State_Sunken;
3376 copy.state |= State_Raised;
3377 copy.state &= ~State_Sunken;
3379 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
3380 : PE_IndicatorSpinUp);
3382 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget);
3383 proxy()->drawPrimitive(PE_PanelButtonBevel, ©, p, widget);
3384 copy.rect.adjust(3, 0, -4, 0);
3385 proxy()->drawPrimitive(pe, ©, p, widget);
3388 if (sb->subControls & SC_SpinBoxDown) {
3389 copy.subControls = SC_SpinBoxDown;
3390 copy.state = sb->state;
3391 QPalette pal2 = sb->palette;
3392 if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled)) {
3393 pal2.setCurrentColorGroup(QPalette::Disabled);
3394 copy.state &= ~State_Enabled;
3396 copy.palette = pal2;
3398 if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken)) {
3399 copy.state |= State_On;
3400 copy.state |= State_Sunken;
3402 copy.state |= State_Raised;
3403 copy.state &= ~State_Sunken;
3405 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
3406 : PE_IndicatorSpinDown);
3408 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget);
3409 proxy()->drawPrimitive(PE_PanelButtonBevel, ©, p, widget);
3410 copy.rect.adjust(3, 0, -4, 0);
3411 proxy()->drawPrimitive(pe, ©, p, widget);
3416#if QT_CONFIG(toolbutton)
3418 if (
const QStyleOptionToolButton *toolbutton
3419 = qstyleoption_cast<
const QStyleOptionToolButton *>(opt)) {
3420 QRect button, menuarea;
3421 button = proxy()->subControlRect(cc, toolbutton, SC_ToolButton, widget);
3422 menuarea = proxy()->subControlRect(cc, toolbutton, SC_ToolButtonMenu, widget);
3424 State bflags = toolbutton->state & ~State_Sunken;
3426 if (bflags & State_AutoRaise) {
3427 if (!(bflags & State_MouseOver) || !(bflags & State_Enabled)) {
3428 bflags &= ~State_Raised;
3431 State mflags = bflags;
3432 if (toolbutton->state & State_Sunken) {
3433 if (toolbutton->activeSubControls & SC_ToolButton)
3434 bflags |= State_Sunken;
3435 mflags |= State_Sunken;
3438 QStyleOption tool = *toolbutton;
3439 if (toolbutton->subControls & SC_ToolButton) {
3440 if (bflags & (State_Sunken | State_On | State_Raised)) {
3442 tool.state = bflags;
3443 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3447 if (toolbutton->state & State_HasFocus) {
3448 QStyleOptionFocusRect fr;
3449 fr.QStyleOption::operator=(*toolbutton);
3450 fr.rect.adjust(3, 3, -3, -3);
3451 if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup)
3452 fr.rect.adjust(0, 0, -proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator,
3453 toolbutton, widget), 0);
3454 proxy()->drawPrimitive(PE_FrameFocusRect, &fr, p, widget);
3456 QStyleOptionToolButton label = *toolbutton;
3457 label.state = bflags;
3458 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget);
3459 label.rect = button.adjusted(fw, fw, -fw, -fw);
3460 proxy()->drawControl(CE_ToolButtonLabel, &label, p, widget);
3462 if (toolbutton->subControls & SC_ToolButtonMenu) {
3463 tool.rect = menuarea;
3464 tool.state = mflags;
3465 if (mflags & (State_Sunken | State_On | State_Raised))
3466 proxy()->drawPrimitive(PE_IndicatorButtonDropDown, &tool, p, widget);
3467 proxy()->drawPrimitive(PE_IndicatorArrowDown, &tool, p, widget);
3468 }
else if (toolbutton->features & QStyleOptionToolButton::HasMenu) {
3469 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, toolbutton, widget);
3470 QRect ir = toolbutton->rect;
3471 QStyleOptionToolButton newBtn = *toolbutton;
3472 newBtn.rect = QRect(ir.right() + 5 - mbi, ir.y() + ir.height() - mbi + 4, mbi - 6, mbi - 6);
3473 newBtn.rect = visualRect(toolbutton->direction, button, newBtn.rect);
3474 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, p, widget);
3480 if (
const QStyleOptionTitleBar *tb = qstyleoption_cast<
const QStyleOptionTitleBar *>(opt)) {
3482 if (opt->subControls & SC_TitleBarLabel) {
3483 QColor left = tb->palette.highlight().color();
3484 QColor right = tb->palette.base().color();
3486 QBrush fillBrush(left);
3487 if (left != right) {
3488 QPoint p1(tb->rect.x(), tb->rect.top() + tb->rect.height()/2);
3489 QPoint p2(tb->rect.right(), tb->rect.top() + tb->rect.height()/2);
3490 QLinearGradient lg(p1, p2);
3491 lg.setColorAt(0, left);
3492 lg.setColorAt(1, right);
3496 p->fillRect(opt->rect, fillBrush);
3498 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarLabel, widget);
3500 p->setPen(tb->palette.highlightedText().color());
3501 p->drawText(ir.x() + 2, ir.y(), ir.width() - 2, ir.height(),
3502 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text);
3508 QStyleOption tool = *tb;
3509 if (tb->subControls & SC_TitleBarCloseButton && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3510 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarCloseButton, widget);
3511 down = tb->activeSubControls & SC_TitleBarCloseButton && (opt->state & State_Sunken);
3512 if ((tb->titleBarFlags & Qt::WindowType_Mask) == Qt::Tool
3513#if QT_CONFIG(dockwidget)
3514 || qobject_cast<
const QDockWidget *>(widget)
3517 pm = proxy()->standardIcon(SP_DockWidgetCloseButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3519 pm = proxy()->standardIcon(SP_TitleBarCloseButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3521 tool.state = down ? State_Sunken : State_Raised;
3522 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3524 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3525 : QPainterStateGuard::InitialState::NoSave);
3527 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3528 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3529 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3532 if (tb->subControls & SC_TitleBarMaxButton
3533 && tb->titleBarFlags & Qt::WindowMaximizeButtonHint
3534 && !(tb->titleBarState & Qt::WindowMaximized)) {
3535 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarMaxButton, widget);
3537 down = tb->activeSubControls & SC_TitleBarMaxButton && (opt->state & State_Sunken);
3538 pm = proxy()->standardIcon(SP_TitleBarMaxButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3540 tool.state = down ? State_Sunken : State_Raised;
3541 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3543 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3544 : QPainterStateGuard::InitialState::NoSave);
3546 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3547 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3548 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3551 if (tb->subControls & SC_TitleBarMinButton
3552 && tb->titleBarFlags & Qt::WindowMinimizeButtonHint
3553 && !(tb->titleBarState & Qt::WindowMinimized)) {
3554 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarMinButton, widget);
3555 down = tb->activeSubControls & SC_TitleBarMinButton && (opt->state & State_Sunken);
3556 pm = proxy()->standardIcon(SP_TitleBarMinButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3558 tool.state = down ? State_Sunken : State_Raised;
3559 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3561 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3562 : QPainterStateGuard::InitialState::NoSave);
3564 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3565 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3566 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3569 bool drawNormalButton = (tb->subControls & SC_TitleBarNormalButton)
3570 && (((tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
3571 && (tb->titleBarState & Qt::WindowMinimized))
3572 || ((tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
3573 && (tb->titleBarState & Qt::WindowMaximized)));
3575 if (drawNormalButton) {
3576 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarNormalButton, widget);
3577 down = tb->activeSubControls & SC_TitleBarNormalButton && (opt->state & State_Sunken);
3578 pm = proxy()->standardIcon(SP_TitleBarNormalButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3580 tool.state = down ? State_Sunken : State_Raised;
3581 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3583 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3584 : QPainterStateGuard::InitialState::NoSave);
3586 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3587 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3588 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3591 if (tb->subControls & SC_TitleBarShadeButton
3592 && tb->titleBarFlags & Qt::WindowShadeButtonHint
3593 && !(tb->titleBarState & Qt::WindowMinimized)) {
3594 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarShadeButton, widget);
3595 down = (tb->activeSubControls & SC_TitleBarShadeButton && (opt->state & State_Sunken));
3596 pm = proxy()->standardIcon(SP_TitleBarShadeButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3598 tool.state = down ? State_Sunken : State_Raised;
3599 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3601 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3602 : QPainterStateGuard::InitialState::NoSave);
3604 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3605 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3606 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3609 if (tb->subControls & SC_TitleBarUnshadeButton
3610 && tb->titleBarFlags & Qt::WindowShadeButtonHint
3611 && tb->titleBarState & Qt::WindowMinimized) {
3612 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarUnshadeButton, widget);
3614 down = tb->activeSubControls & SC_TitleBarUnshadeButton && (opt->state & State_Sunken);
3615 pm = proxy()->standardIcon(SP_TitleBarUnshadeButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3617 tool.state = down ? State_Sunken : State_Raised;
3618 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3620 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3621 : QPainterStateGuard::InitialState::NoSave);
3623 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3624 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3625 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3627 if (tb->subControls & SC_TitleBarContextHelpButton
3628 && tb->titleBarFlags & Qt::WindowContextHelpButtonHint) {
3629 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarContextHelpButton, widget);
3631 down = tb->activeSubControls & SC_TitleBarContextHelpButton && (opt->state & State_Sunken);
3632 pm = proxy()->standardIcon(SP_TitleBarContextHelpButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3634 tool.state = down ? State_Sunken : State_Raised;
3635 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3637 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3638 : QPainterStateGuard::InitialState::NoSave);
3640 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3641 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3642 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3644 if (tb->subControls & SC_TitleBarSysMenu && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3645 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarSysMenu, widget);
3646 if (!tb->icon.isNull()) {
3647 tb->icon.paint(p, ir);
3649 int iconSize = proxy()->pixelMetric(PM_SmallIconSize, tb, widget);
3650 pm = proxy()->standardIcon(SP_TitleBarMenuButton, &tool, widget).pixmap(QSize(iconSize, iconSize), QStyleHelper::getDpr(p));
3652 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3659 if (
const QStyleOptionSlider *dial = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
3661 QPainterStateGuard psg(p);
3664 if (p->paintEngine()->hasFeature(QPaintEngine::Antialiasing))
3665 p->setRenderHint(QPainter::Antialiasing);
3667 int width = dial->rect.width();
3668 int height = dial->rect.height();
3669 qreal r = qMin(width, height) / 2;
3671 qreal dx = dial->rect.x() + d_ + (width - 2 * r) / 2 + 1;
3672 qreal dy = dial->rect.y() + d_ + (height - 2 * r) / 2 + 1;
3673 QRect br = QRect(
int(dx),
int(dy),
int(r * 2 - 2 * d_ - 2),
int(r * 2 - 2 * d_ - 2));
3675 QPalette pal = opt->palette;
3677 if (dial->subControls & QStyle::SC_DialTickmarks) {
3678 p->setPen(pal.windowText().color());
3679 p->drawLines(QStyleHelper::calcLines(dial));
3682 if (dial->state & State_Enabled) {
3683 p->setBrush(pal.brush(QPalette::ColorRole(proxy()->styleHint(SH_Dial_BackgroundRole,
3685 p->setPen(Qt::NoPen);
3687 p->setBrush(Qt::NoBrush);
3689 p->setPen(pal.dark().color());
3690 p->drawArc(br, 60 * 16, 180 * 16);
3691 p->setPen(pal.light().color());
3692 p->drawArc(br, 240 * 16, 180 * 16);
3695 const auto arrow = calcArrow(dial, a);
3697 p->setPen(Qt::NoPen);
3698 p->setBrush(pal.button());
3699 p->drawPolygon(arrow.data(),
int(arrow.size()));
3701 a = QStyleHelper::angle(QPointF(width / 2, height / 2), arrow[0]);
3702 p->setBrush(Qt::NoBrush);
3704 if (a <= 0 || a > 200) {
3705 p->setPen(pal.light().color());
3706 p->drawLine(arrow[2], arrow[0]);
3707 p->drawLine(arrow[1], arrow[2]);
3708 p->setPen(pal.dark().color());
3709 p->drawLine(arrow[0], arrow[1]);
3710 }
else if (a > 0 && a < 45) {
3711 p->setPen(pal.light().color());
3712 p->drawLine(arrow[2], arrow[0]);
3713 p->setPen(pal.dark().color());
3714 p->drawLine(arrow[1], arrow[2]);
3715 p->drawLine(arrow[0], arrow[1]);
3716 }
else if (a >= 45 && a < 135) {
3717 p->setPen(pal.dark().color());
3718 p->drawLine(arrow[2], arrow[0]);
3719 p->drawLine(arrow[1], arrow[2]);
3720 p->setPen(pal.light().color());
3721 p->drawLine(arrow[0], arrow[1]);
3722 }
else if (a >= 135 && a < 200) {
3723 p->setPen(pal.dark().color());
3724 p->drawLine(arrow[2], arrow[0]);
3725 p->setPen(pal.light().color());
3726 p->drawLine(arrow[0], arrow[1]);
3727 p->drawLine(arrow[1], arrow[2]);
3731 QStyleOptionFocusRect fropt;
3732 fropt.rect = dial->rect;
3733 fropt.state = dial->state;
3734 fropt.palette = dial->palette;
3735 if (fropt.state & QStyle::State_HasFocus) {
3736 br.adjust(0, 0, 2, 2);
3737 if (dial->subControls & SC_DialTickmarks) {
3738 int r = qMin(width, height) / 2;
3739 br.translate(-r / 6, - r / 6);
3740 br.setWidth(br.width() + r / 3);
3741 br.setHeight(br.height() + r / 3);
3743 fropt.rect = br.adjusted(-2, -2, 2, 2);
3744 proxy()->drawPrimitive(QStyle::PE_FrameFocusRect, &fropt, p, widget);
3749#if QT_CONFIG(groupbox)
3751 if (
const QStyleOptionGroupBox *groupBox = qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
3753 QRect textRect = proxy()->subControlRect(CC_GroupBox, opt, SC_GroupBoxLabel, widget);
3754 QRect checkBoxRect = proxy()->subControlRect(CC_GroupBox, opt, SC_GroupBoxCheckBox, widget);
3755 if (groupBox->subControls & QStyle::SC_GroupBoxFrame) {
3756 QStyleOptionFrame frame;
3757 frame.QStyleOption::operator=(*groupBox);
3758 frame.features = groupBox->features;
3759 frame.lineWidth = groupBox->lineWidth;
3760 frame.midLineWidth = groupBox->midLineWidth;
3761 frame.rect = proxy()->subControlRect(CC_GroupBox, opt, SC_GroupBoxFrame, widget);
3762 QPainterStateGuard psg(p);
3763 QRegion region(groupBox->rect);
3764 if (!groupBox->text.isEmpty()) {
3765 bool ltr = groupBox->direction == Qt::LeftToRight;
3767 if (groupBox->subControls & QStyle::SC_GroupBoxCheckBox) {
3768 finalRect = checkBoxRect.united(textRect);
3769 finalRect.adjust(ltr ? -4 : 0, 0, ltr ? 0 : 4, 0);
3771 finalRect = textRect;
3773 region -= finalRect;
3775 p->setClipRegion(region);
3776 proxy()->drawPrimitive(PE_FrameGroupBox, &frame, p, widget);
3780 if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
3781 QColor textColor = groupBox->textColor;
3782 if (textColor.isValid())
3783 p->setPen(textColor);
3784 int alignment =
int(groupBox->textAlignment);
3785 if (!proxy()->styleHint(QStyle::SH_UnderlineShortcut, opt, widget))
3786 alignment |= Qt::TextHideMnemonic;
3788 proxy()->drawItemText(p, textRect, Qt::TextShowMnemonic | Qt::AlignHCenter | alignment,
3789 groupBox->palette, groupBox->state & State_Enabled, groupBox->text,
3790 textColor.isValid() ? QPalette::NoRole : QPalette::WindowText);
3792 if (groupBox->state & State_HasFocus) {
3793 QStyleOptionFocusRect fropt;
3794 fropt.QStyleOption::operator=(*groupBox);
3795 fropt.rect = textRect;
3796 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
3801 if (groupBox->subControls & SC_GroupBoxCheckBox) {
3802 QStyleOptionButton box;
3803 box.QStyleOption::operator=(*groupBox);
3804 box.rect = checkBoxRect;
3805 proxy()->drawPrimitive(PE_IndicatorCheckBox, &box, p, widget);
3810#if QT_CONFIG(mdiarea)
3811 case CC_MdiControls:
3813 QStyleOptionButton btnOpt;
3814 btnOpt.QStyleOption::operator=(*opt);
3815 btnOpt.state &= ~State_MouseOver;
3818 const int buttonIconMetric = proxy()->pixelMetric(PM_TitleBarButtonIconSize, &btnOpt, widget);
3819 const QSize buttonIconSize(buttonIconMetric, buttonIconMetric);
3820 if (opt->subControls & QStyle::SC_MdiCloseButton) {
3821 if (opt->activeSubControls & QStyle::SC_MdiCloseButton && (opt->state & State_Sunken)) {
3822 btnOpt.state |= State_Sunken;
3823 btnOpt.state &= ~State_Raised;
3824 bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget);
3825 bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget);
3827 btnOpt.state |= State_Raised;
3828 btnOpt.state &= ~State_Sunken;
3832 btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiCloseButton, widget);
3833 proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p, widget);
3834 QPixmap pm = proxy()->standardIcon(SP_TitleBarCloseButton).pixmap(buttonIconSize, QStyleHelper::getDpr(p));
3835 proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm);
3837 if (opt->subControls & QStyle::SC_MdiNormalButton) {
3838 if (opt->activeSubControls & QStyle::SC_MdiNormalButton && (opt->state & State_Sunken)) {
3839 btnOpt.state |= State_Sunken;
3840 btnOpt.state &= ~State_Raised;
3841 bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget);
3842 bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget);
3844 btnOpt.state |= State_Raised;
3845 btnOpt.state &= ~State_Sunken;
3849 btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiNormalButton, widget);
3850 proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p, widget);
3851 QPixmap pm = proxy()->standardIcon(SP_TitleBarNormalButton).pixmap(buttonIconSize, QStyleHelper::getDpr(p));
3852 proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm);
3854 if (opt->subControls & QStyle::SC_MdiMinButton) {
3855 if (opt->activeSubControls & QStyle::SC_MdiMinButton && (opt->state & State_Sunken)) {
3856 btnOpt.state |= State_Sunken;
3857 btnOpt.state &= ~State_Raised;
3858 bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget);
3859 bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget);
3861 btnOpt.state |= State_Raised;
3862 btnOpt.state &= ~State_Sunken;
3866 btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiMinButton, widget);
3867 proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p, widget);
3868 QPixmap pm = proxy()->standardIcon(SP_TitleBarMinButton).pixmap(buttonIconSize, QStyleHelper::getDpr(p));
3869 proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm);
3875 qCWarning(lcCommonStyle,
"QCommonStyle::drawComplexControl: Control %d not handled", cc);
4019QRect QCommonStyle::subControlRect(ComplexControl cc,
const QStyleOptionComplex *opt,
4020 SubControl sc,
const QWidget *widget)
const
4024#if QT_CONFIG(slider)
4026 if (
const QStyleOptionSlider *slider = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
4027 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider, widget);
4028 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
4031 case SC_SliderHandle: {
4033 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
4034 bool horizontal = slider->orientation == Qt::Horizontal;
4035 sliderPos = sliderPositionFromValue(slider->minimum, slider->maximum,
4036 slider->sliderPosition,
4037 (horizontal ? slider->rect.width()
4038 : slider->rect.height()) - len,
4039 slider->upsideDown);
4041 ret.setRect(slider->rect.x() + sliderPos, slider->rect.y() + tickOffset, len, thickness);
4043 ret.setRect(slider->rect.x() + tickOffset, slider->rect.y() + sliderPos, thickness, len);
4045 case SC_SliderGroove:
4046 if (slider->orientation == Qt::Horizontal)
4047 ret.setRect(slider->rect.x(), slider->rect.y() + tickOffset,
4048 slider->rect.width(), thickness);
4050 ret.setRect(slider->rect.x() + tickOffset, slider->rect.y(),
4051 thickness, slider->rect.height());
4056 ret = visualRect(slider->direction, slider->rect, ret);
4060#if QT_CONFIG(scrollbar)
4062 if (
const QStyleOptionSlider *scrollbar = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
4063 const QRect scrollBarRect = scrollbar->rect;
4065 if (!proxy()->styleHint(SH_ScrollBar_Transient, scrollbar, widget))
4066 sbextent = proxy()->pixelMetric(PM_ScrollBarExtent, scrollbar, widget);
4067 int maxlen = ((scrollbar->orientation == Qt::Horizontal) ?
4068 scrollBarRect.width() : scrollBarRect.height()) - (sbextent * 2);
4072 if (scrollbar->maximum != scrollbar->minimum) {
4073 uint range = scrollbar->maximum - scrollbar->minimum;
4074 sliderlen = (qint64(scrollbar->pageStep) * maxlen) / (range + scrollbar->pageStep);
4076 int slidermin = proxy()->pixelMetric(PM_ScrollBarSliderMin, scrollbar, widget);
4077 if (sliderlen < slidermin || range > INT_MAX / 2)
4078 sliderlen = slidermin;
4079 if (sliderlen > maxlen)
4085 int sliderstart = sbextent + sliderPositionFromValue(scrollbar->minimum,
4087 scrollbar->sliderPosition,
4089 scrollbar->upsideDown);
4092 case SC_ScrollBarSubLine:
4093 if (scrollbar->orientation == Qt::Horizontal) {
4094 int buttonWidth = qMin(scrollBarRect.width() / 2, sbextent);
4095 ret.setRect(0, 0, buttonWidth, scrollBarRect.height());
4097 int buttonHeight = qMin(scrollBarRect.height() / 2, sbextent);
4098 ret.setRect(0, 0, scrollBarRect.width(), buttonHeight);
4101 case SC_ScrollBarAddLine:
4102 if (scrollbar->orientation == Qt::Horizontal) {
4103 int buttonWidth = qMin(scrollBarRect.width()/2, sbextent);
4104 ret.setRect(scrollBarRect.width() - buttonWidth, 0, buttonWidth, scrollBarRect.height());
4106 int buttonHeight = qMin(scrollBarRect.height()/2, sbextent);
4107 ret.setRect(0, scrollBarRect.height() - buttonHeight, scrollBarRect.width(), buttonHeight);
4110 case SC_ScrollBarSubPage:
4111 if (scrollbar->orientation == Qt::Horizontal)
4112 ret.setRect(sbextent, 0, sliderstart - sbextent, scrollBarRect.height());
4114 ret.setRect(0, sbextent, scrollBarRect.width(), sliderstart - sbextent);
4116 case SC_ScrollBarAddPage:
4117 if (scrollbar->orientation == Qt::Horizontal)
4118 ret.setRect(sliderstart + sliderlen, 0,
4119 maxlen - sliderstart - sliderlen + sbextent, scrollBarRect.height());
4121 ret.setRect(0, sliderstart + sliderlen, scrollBarRect.width(),
4122 maxlen - sliderstart - sliderlen + sbextent);
4124 case SC_ScrollBarGroove:
4125 if (scrollbar->orientation == Qt::Horizontal)
4126 ret.setRect(sbextent, 0, scrollBarRect.width() - sbextent * 2,
4127 scrollBarRect.height());
4129 ret.setRect(0, sbextent, scrollBarRect.width(),
4130 scrollBarRect.height() - sbextent * 2);
4132 case SC_ScrollBarSlider:
4133 if (scrollbar->orientation == Qt::Horizontal)
4134 ret.setRect(sliderstart, 0, sliderlen, scrollBarRect.height());
4136 ret.setRect(0, sliderstart, scrollBarRect.width(), sliderlen);
4141 ret = visualRect(scrollbar->direction, scrollBarRect, ret);
4145#if QT_CONFIG(spinbox)
4147 if (
const QStyleOptionSpinBox *spinbox = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
4149 int fw = spinbox->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget) : 0;
4150 bs.setHeight(qMax(8, spinbox->rect.height()/2 - fw));
4152 bs.setWidth(qMax(16, qMin(bs.height() * 8 / 5, spinbox->rect.width() / 4)));
4153 int y = fw + spinbox->rect.y();
4155 x = spinbox->rect.x() + spinbox->rect.width() - fw - bs.width();
4160 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
4162 ret = QRect(x, y, bs.width(), bs.height());
4164 case SC_SpinBoxDown:
4165 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
4168 ret = QRect(x, y + bs.height(), bs.width(), bs.height());
4170 case SC_SpinBoxEditField:
4171 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons) {
4172 ret = QRect(lx, fw, spinbox->rect.width() - 2*fw, spinbox->rect.height() - 2*fw);
4174 ret = QRect(lx, fw, rx, spinbox->rect.height() - 2*fw);
4177 case SC_SpinBoxFrame:
4178 ret = spinbox->rect;
4183 ret = visualRect(spinbox->direction, spinbox->rect, ret);
4187#if QT_CONFIG(toolbutton)
4189 if (
const QStyleOptionToolButton *tb = qstyleoption_cast<
const QStyleOptionToolButton *>(opt)) {
4193 if (tb->features.testFlag(QStyleOptionToolButton::MenuButtonPopup)) {
4194 const int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, tb, widget);
4195 ret.adjust(0, 0, -mbi, 0);
4198 case SC_ToolButtonMenu:
4199 if (tb->features.testFlag(QStyleOptionToolButton::MenuButtonPopup)) {
4200 const int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, tb, widget);
4201 ret.adjust(ret.width() - mbi, 0, 0, 0);
4207 ret = visualRect(tb->direction, tb->rect, ret);
4211#if QT_CONFIG(combobox)
4213 if (
const QStyleOptionComboBox *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
4214 const qreal dpi = QStyleHelper::dpi(opt);
4215 const int x = cb->rect.x(), y = cb->rect.y(), wi = cb->rect.width(), he = cb->rect.height();
4216 const int margin = cb->frame ? qRound(QStyleHelper::dpiScaled(3, dpi)) : 0;
4217 const int bmarg = cb->frame ? qRound(QStyleHelper::dpiScaled(2, dpi)) : 0;
4218 const int xpos = x + wi - bmarg - qRound(QStyleHelper::dpiScaled(16, dpi));
4222 case SC_ComboBoxFrame:
4225 case SC_ComboBoxArrow:
4226 ret.setRect(xpos, y + bmarg, qRound(QStyleHelper::dpiScaled(16, opt)), he - 2*bmarg);
4228 case SC_ComboBoxEditField:
4229 ret.setRect(x + margin, y + margin, wi - 2 * margin - qRound(QStyleHelper::dpiScaled(16, dpi)), he - 2 * margin);
4231 case SC_ComboBoxListBoxPopup:
4237 ret = visualRect(cb->direction, cb->rect, ret);
4242 if (
const QStyleOptionTitleBar *tb = qstyleoption_cast<
const QStyleOptionTitleBar *>(opt)) {
4243 const int controlMargin = 2;
4244 const int controlHeight = tb->rect.height() - controlMargin *2;
4245 const int delta = controlHeight + controlMargin;
4248 bool isMinimized = tb->titleBarState & Qt::WindowMinimized;
4249 bool isMaximized = tb->titleBarState & Qt::WindowMaximized;
4252 case SC_TitleBarLabel:
4253 if (tb->titleBarFlags & (Qt::WindowTitleHint | Qt::WindowSystemMenuHint)) {
4255 if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
4256 ret.adjust(delta, 0, -delta, 0);
4257 if (tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
4258 ret.adjust(0, 0, -delta, 0);
4259 if (tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
4260 ret.adjust(0, 0, -delta, 0);
4261 if (tb->titleBarFlags & Qt::WindowShadeButtonHint)
4262 ret.adjust(0, 0, -delta, 0);
4263 if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
4264 ret.adjust(0, 0, -delta, 0);
4267 case SC_TitleBarContextHelpButton:
4268 if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
4271 case SC_TitleBarMinButton:
4272 if (!isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
4274 else if (sc == SC_TitleBarMinButton)
4277 case SC_TitleBarNormalButton:
4278 if (isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
4280 else if (isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
4282 else if (sc == SC_TitleBarNormalButton)
4285 case SC_TitleBarMaxButton:
4286 if (!isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
4288 else if (sc == SC_TitleBarMaxButton)
4291 case SC_TitleBarShadeButton:
4292 if (!isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
4294 else if (sc == SC_TitleBarShadeButton)
4297 case SC_TitleBarUnshadeButton:
4298 if (isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
4300 else if (sc == SC_TitleBarUnshadeButton)
4303 case SC_TitleBarCloseButton:
4304 if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
4306 else if (sc == SC_TitleBarCloseButton)
4308 ret.setRect(tb->rect.right() - offset, tb->rect.top() + controlMargin,
4309 controlHeight, controlHeight);
4311 case SC_TitleBarSysMenu:
4312 if (tb->titleBarFlags & Qt::WindowSystemMenuHint) {
4313 ret.setRect(tb->rect.left() + controlMargin, tb->rect.top() + controlMargin,
4314 controlHeight, controlHeight);
4320 ret = visualRect(tb->direction, tb->rect, ret);
4323#if QT_CONFIG(groupbox)
4325 if (
const QStyleOptionGroupBox *groupBox = qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
4327 case SC_GroupBoxFrame:
4328 case SC_GroupBoxContents: {
4331 int verticalAlignment = proxy()->styleHint(SH_GroupBox_TextLabelVerticalAlignment, groupBox, widget);
4332 bool hasCheckBox = groupBox->subControls & QStyle::SC_GroupBoxCheckBox;
4333 if (groupBox->text.size() || hasCheckBox) {
4334 int checkBoxHeight = hasCheckBox ? proxy()->pixelMetric(PM_IndicatorHeight, groupBox, widget) : 0;
4335 topHeight = qMax(groupBox->fontMetrics.height(), checkBoxHeight);
4336 if (verticalAlignment & Qt::AlignVCenter)
4337 topMargin = topHeight / 2;
4338 else if (verticalAlignment & Qt::AlignTop)
4339 topMargin = topHeight + proxy()->pixelMetric(PM_FocusFrameVMargin, groupBox, widget);
4342 QRect frameRect = groupBox->rect;
4343 frameRect.setTop(frameRect.top() + topMargin);
4345 if (sc == SC_GroupBoxFrame) {
4351 if ((groupBox->features & QStyleOptionFrame::Flat) == 0)
4352 frameWidth = proxy()->pixelMetric(PM_DefaultFrameWidth, groupBox, widget);
4353 ret = frameRect.adjusted(frameWidth, frameWidth + topHeight - topMargin,
4354 -frameWidth, -frameWidth);
4357 case SC_GroupBoxCheckBox:
4358 case SC_GroupBoxLabel: {
4359 QFontMetrics fontMetrics = groupBox->fontMetrics;
4360 int th = fontMetrics.height();
4361 int tw = fontMetrics.size(Qt::TextShowMnemonic, groupBox->text + u' ').width();
4362 int marg = (groupBox->features & QStyleOptionFrame::Flat) ? 0 : 8;
4363 ret = groupBox->rect.adjusted(marg, 0, -marg, 0);
4365 int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, opt, widget);
4366 int indicatorHeight = proxy()->pixelMetric(PM_IndicatorHeight, opt, widget);
4367 int indicatorSpace = proxy()->pixelMetric(PM_CheckBoxLabelSpacing, opt, widget) - 1;
4368 bool hasCheckBox = groupBox->subControls & QStyle::SC_GroupBoxCheckBox;
4369 int checkBoxWidth = hasCheckBox ? (indicatorWidth + indicatorSpace) : 0;
4370 int checkBoxHeight = hasCheckBox ? indicatorHeight : 0;
4372 int h = qMax(th, checkBoxHeight);
4376 QRect totalRect = alignedRect(groupBox->direction, groupBox->textAlignment,
4377 QSize(tw + checkBoxWidth, h), ret);
4381 bool ltr = groupBox->direction == Qt::LeftToRight;
4384 if (sc == SC_GroupBoxCheckBox) {
4385 left = ltr ? totalRect.left() : (totalRect.right() - indicatorWidth);
4386 int top = totalRect.top() + (h - checkBoxHeight) / 2;
4387 totalRect.setRect(left, top, indicatorWidth, indicatorHeight);
4390 left = ltr ? (totalRect.left() + checkBoxWidth - 2) : totalRect.left();
4391 int top = totalRect.top() + (h - th) / 2;
4392 totalRect.setRect(left, top, totalRect.width() - checkBoxWidth, th);
4405#if QT_CONFIG(mdiarea)
4406 case CC_MdiControls:
4408 int numSubControls = 0;
4409 if (opt->subControls & SC_MdiCloseButton)
4411 if (opt->subControls & SC_MdiMinButton)
4413 if (opt->subControls & SC_MdiNormalButton)
4415 if (numSubControls == 0)
4418 int buttonWidth = opt->rect.width() / numSubControls - 1;
4421 case SC_MdiCloseButton:
4423 if (numSubControls == 1)
4425 offset += buttonWidth + 2;
4427 case SC_MdiNormalButton:
4431 if (numSubControls == 1 || (numSubControls == 2 && !(opt->subControls & SC_MdiMinButton)))
4433 if (opt->subControls & SC_MdiNormalButton)
4434 offset += buttonWidth;
4443 if (numSubControls == 1)
4445 ret = QRect(offset, 0, buttonWidth, opt->rect.height());
4450 qCWarning(lcCommonStyle,
"QCommonStyle::subControlRect: Case %d not handled", cc);
4452#if !QT_CONFIG(slider) && !QT_CONFIG(spinbox) && !QT_CONFIG(toolbutton) && !QT_CONFIG(groupbox)
5834QIcon QCommonStylePrivate::iconFromResourceTheme(QCommonStyle::StandardPixmap standardIcon,
5835 const QStyleOption *option,
5836 const QWidget *widget)
const
5838 Q_Q(
const QCommonStyle);
5840#ifndef QT_NO_IMAGEFORMAT_PNG
5841 switch (standardIcon) {
5842 case QStyle::SP_MessageBoxInformation:
5843 addIconFiles(u"information-", pngIconSizes, icon);
5845 case QStyle::SP_MessageBoxWarning:
5846 addIconFiles(u"warning-", pngIconSizes, icon);
5848 case QStyle::SP_MessageBoxCritical:
5849 addIconFiles(u"critical-", pngIconSizes, icon);
5851 case QStyle::SP_MessageBoxQuestion:
5852 addIconFiles(u"question-", pngIconSizes, icon);
5854 case QStyle::SP_FileDialogStart:
5855 addIconFiles(u"filedialog_start-", pngIconSizes, icon);
5857 case QStyle::SP_FileDialogEnd:
5858 addIconFiles(u"filedialog_end-", pngIconSizes, icon);
5860 case QStyle::SP_TitleBarMinButton:
5861 addIconFiles(u"titlebar-min-", titleBarSizes, icon);
5863 case QStyle::SP_TitleBarMaxButton:
5864 addIconFiles(u"titlebar-max-", titleBarSizes, icon);
5866 case QStyle::SP_TitleBarShadeButton:
5867 addIconFiles(u"titlebar-shade-", titleBarSizes, icon);
5869 case QStyle::SP_TitleBarUnshadeButton:
5870 addIconFiles(u"titlebar-unshade-", titleBarSizes, icon);
5872 case QStyle::SP_TitleBarContextHelpButton:
5873 addIconFiles(u"titlebar-contexthelp-", titleBarSizes, icon);
5875 case QStyle::SP_FileDialogNewFolder:
5876 addIconFiles(u"newdirectory-", pngIconSizes, icon);
5878 case QStyle::SP_FileDialogBack:
5879 return q->proxy()->standardIcon(QStyle::SP_ArrowBack, option, widget);
5880 case QStyle::SP_FileDialogToParent:
5881 return q->proxy()->standardIcon(QStyle::SP_ArrowUp, option, widget);
5882 case QStyle::SP_FileDialogDetailedView:
5883 addIconFiles(u"viewdetailed-", pngIconSizes, icon);
5885 case QStyle::SP_FileDialogInfoView:
5886 addIconFiles(u"fileinfo-", pngIconSizes, icon);
5888 case QStyle::SP_FileDialogContentsView:
5889 addIconFiles(u"filecontents-", pngIconSizes, icon);
5891 case QStyle::SP_FileDialogListView:
5892 addIconFiles(u"viewlist-", pngIconSizes, icon);
5894 case QStyle::SP_DialogOkButton:
5895 addIconFiles(u"standardbutton-ok-", pngIconSizes, icon);
5897 case QStyle::SP_DialogCancelButton:
5898 addIconFiles(u"standardbutton-cancel-", pngIconSizes, icon);
5900 case QStyle::SP_DialogHelpButton:
5901 addIconFiles(u"standardbutton-help-", pngIconSizes, icon);
5903 case QStyle::SP_DialogOpenButton:
5904 addIconFiles(u"standardbutton-open-", pngIconSizes, icon);
5906 case QStyle::SP_DialogSaveButton:
5907 addIconFiles(u"standardbutton-save-", pngIconSizes, icon);
5909 case QStyle::SP_DialogCloseButton:
5910 addIconFiles(u"standardbutton-close-", pngIconSizes, icon);
5912 case QStyle::SP_DialogApplyButton:
5913 addIconFiles(u"standardbutton-apply-", pngIconSizes, icon);
5915 case QStyle::SP_DialogResetButton:
5916 addIconFiles(u"standardbutton-clear-", pngIconSizes, icon);
5918 case QStyle::SP_DialogDiscardButton:
5919 addIconFiles(u"standardbutton-delete-", pngIconSizes, icon);
5921 case QStyle::SP_DialogYesButton:
5922 addIconFiles(u"standardbutton-yes-", pngIconSizes, icon);
5924 case QStyle::SP_DialogNoButton:
5925 addIconFiles(u"standardbutton-no-", pngIconSizes, icon);
5927 case QStyle::SP_CommandLink:
5928 case QStyle::SP_ArrowForward:
5929 return q->proxy()->standardIcon(rtl(option) ? QStyle::SP_ArrowLeft
5930 : QStyle::SP_ArrowRight,
5932 case QStyle::SP_ArrowBack:
5933 return q->proxy()->standardIcon(rtl(option) ? QStyle::SP_ArrowRight
5934 : QStyle::SP_ArrowLeft,
5936 case QStyle::SP_ArrowLeft:
5937 addIconFiles(u"arrow-left-", pngIconSizes, icon);
5939 case QStyle::SP_ArrowRight:
5940 addIconFiles(u"arrow-right-", pngIconSizes, icon);
5942 case QStyle::SP_ArrowUp:
5943 addIconFiles(u"arrow-up-", pngIconSizes, icon);
5945 case QStyle::SP_ArrowDown:
5946 addIconFiles(u"arrow-down-", pngIconSizes, icon);
5948 case QStyle::SP_DirHomeIcon:
5949 case QStyle::SP_DirIcon:
5950 addIconFiles(u"dirclosed-", pngIconSizes, icon, QIcon::Normal, QIcon::Off);
5951 addIconFiles(u"diropen-", pngIconSizes, icon, QIcon::Normal, QIcon::On);
5953 case QStyle::SP_DirOpenIcon:
5954 addIconFiles(u"diropen-", pngIconSizes, icon);
5956 case QStyle::SP_DirClosedIcon:
5957 addIconFiles(u"dirclosed-", pngIconSizes, icon);
5959 case QStyle::SP_DirLinkIcon:
5960 addIconFiles(u"dirlink-", pngIconSizes, icon);
5962 case QStyle::SP_DriveCDIcon:
5963 addIconFiles(u"cdr-", pngIconSizes, icon);
5965 case QStyle::SP_DriveFDIcon:
5966 addIconFiles(u"floppy-", pngIconSizes, icon);
5968 case QStyle::SP_DriveHDIcon:
5969 addIconFiles(u"harddrive-", pngIconSizes, icon);
5971 case QStyle::SP_DriveDVDIcon:
5972 addIconFiles(u"dvd-", pngIconSizes, icon);
5974 case QStyle::SP_DriveNetIcon:
5975 addIconFiles(u"networkdrive-", pngIconSizes, icon);
5977 case QStyle::SP_FileIcon:
5978 addIconFiles(u"file-", pngIconSizes, icon);
5980 case QStyle::SP_FileLinkIcon:
5981 addIconFiles(u"filelink-", pngIconSizes, icon);
5983 case QStyle::SP_DesktopIcon:
5984 addIconFiles(u"desktop-", {16, 32}, icon);
5986 case QStyle::SP_TrashIcon:
5987 addIconFiles(u"trash-", pngIconSizes, icon);
5989 case QStyle::SP_ComputerIcon:
5990 addIconFiles(u"computer-", {16, 32}, icon);
5992 case QStyle::SP_BrowserReload:
5993 addIconFiles(u"refresh-", {24, 32}, icon);
5995 case QStyle::SP_BrowserStop:
5996 addIconFiles(u"stop-", {24, 32}, icon);
5998 case QStyle::SP_MediaPlay:
5999 addIconFiles(u"media-play-", pngIconSizes, icon);
6001 case QStyle::SP_MediaPause:
6002 addIconFiles(u"media-pause-", pngIconSizes, icon);
6004 case QStyle::SP_MediaStop:
6005 addIconFiles(u"media-stop-", pngIconSizes, icon);
6007 case QStyle::SP_MediaSeekForward:
6008 addIconFiles(u"media-seek-forward-", pngIconSizes, icon);
6010 case QStyle::SP_MediaSeekBackward:
6011 addIconFiles(u"media-seek-backward-", pngIconSizes, icon);
6013 case QStyle::SP_MediaSkipForward:
6014 addIconFiles(u"media-skip-forward-", pngIconSizes, icon);
6016 case QStyle::SP_MediaSkipBackward:
6017 addIconFiles(u"media-skip-backward-", pngIconSizes, icon);
6019 case QStyle::SP_MediaVolume:
6020 addIconFiles(u"media-volume-", pngIconSizes, icon);
6022 case QStyle::SP_MediaVolumeMuted:
6023 addIconFiles(u"media-volume-muted-", pngIconSizes, icon);
6025 case QStyle::SP_TitleBarCloseButton:
6026 case QStyle::SP_DockWidgetCloseButton:
6027 addIconFiles(u"closedock-", dockTitleIconSizes, icon);
6029 case QStyle::SP_TitleBarMenuButton:
6030# ifndef QT_NO_IMAGEFORMAT_XPM
6031 icon.addPixmap(titleBarMenuCachedPixmapFromXPM());
6033 icon.addFile(
":/qt-project.org/qmessagebox/images/qtlogo-64.png"_L1);
6035 case QStyle::SP_TitleBarNormalButton:
6036 addIconFiles(u"normalizedockup-", dockTitleIconSizes, icon);
6038 case QStyle::SP_ToolBarHorizontalExtensionButton:
6039 addIconFiles(rtl(option) ? u"toolbar-ext-h-rtl-"_sv : u"toolbar-ext-h-"_sv, toolBarExtHSizes, icon);
6041 case QStyle::SP_ToolBarVerticalExtensionButton:
6042 addIconFiles(u"toolbar-ext-v-", toolBarExtVSizes, icon);
6044 case QStyle::SP_TabCloseButton:
6045 addIconFiles(u"standardbutton-closetab-", pngIconSizes, icon, QIcon::Normal, QIcon::Off);
6046 addIconFiles(u"standardbutton-closetab-down-", pngIconSizes, icon, QIcon::Normal, QIcon::On);
6047 addIconFiles(u"standardbutton-closetab-hover-", pngIconSizes, icon, QIcon::Active, QIcon::Off);
6049 case QStyle::SP_LineEditClearButton:
6050 addIconFiles(u"cleartext-", pngIconSizes, icon);
6056 Q_UNUSED(standardIcon);