134void QCommonStyle::drawPrimitive(PrimitiveElement pe,
const QStyleOption *opt, QPainter *p,
135 const QWidget *widget)
const
137 Q_D(
const QCommonStyle);
139 case PE_FrameButtonBevel:
140 case PE_FrameButtonTool:
141 qDrawShadeRect(p, opt->rect, opt->palette,
142 opt->state & (State_Sunken | State_On), 1, 0);
144 case PE_PanelButtonCommand:
145 case PE_PanelButtonBevel:
146 case PE_PanelButtonTool:
147 case PE_IndicatorButtonDropDown:
148 qDrawShadePanel(p, opt->rect, opt->palette,
149 opt->state & (State_Sunken | State_On), 1,
150 &opt->palette.brush(QPalette::Button));
152 case PE_IndicatorItemViewItemCheck:
153 proxy()->drawPrimitive(PE_IndicatorCheckBox, opt, p, widget);
155 case PE_IndicatorCheckBox:
156 if (opt->state & State_NoChange) {
157 p->setPen(opt->palette.windowText().color());
158 p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));
159 p->drawRect(opt->rect);
160 p->drawLine(opt->rect.topLeft(), opt->rect.bottomRight());
162 qDrawShadePanel(p, opt->rect.x(), opt->rect.y(), opt->rect.width(), opt->rect.height(),
163 opt->palette, opt->state & (State_Sunken | State_On), 1,
164 &opt->palette.brush(QPalette::Button));
167 case PE_IndicatorRadioButton: {
168 QRect ir = opt->rect;
169 p->setPen(opt->palette.dark().color());
170 p->drawArc(opt->rect, 0, 5760);
171 if (opt->state & (State_Sunken | State_On)) {
172 ir.adjust(2, 2, -2, -2);
173 p->setBrush(opt->palette.windowText());
177 case PE_FrameFocusRect:
178 if (
const QStyleOptionFocusRect *fropt = qstyleoption_cast<
const QStyleOptionFocusRect *>(opt)) {
179 QColor bg = fropt->backgroundColor;
183 bg.getHsv(&h, &s, &v);
189 color = opt->palette.windowText().color();
191 const QRect focusRect = opt->rect.adjusted(1, 1, -1, -1);
192 qDrawPlainRect(p, focusRect, color, 1);
195 case PE_IndicatorMenuCheckMark: {
196 const int markW = opt->rect.width() > 7 ? 7 : opt->rect.width();
197 const int markH = markW;
198 int posX = opt->rect.x() + (opt->rect.width() - markW)/2 + 1;
199 int posY = opt->rect.y() + (opt->rect.height() - markH)/2;
207 for (i = 0; i < markW/2; ++i) {
208 a << QLineF(xx, yy, xx, yy + 2);
213 for (; i < markH; ++i) {
214 a << QLineF(xx, yy, xx, yy + 2);
218 if (!(opt->state & State_Enabled) && !(opt->state & State_On)) {
219 QPainterStateGuard psg(p);
221 p->setPen(opt->palette.light().color());
224 p->setPen((opt->state & State_On) ? opt->palette.highlightedText().color() : opt->palette.text().color());
229 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
230 if (pe == PE_FrameMenu || (frame->state & State_Sunken) || (frame->state & State_Raised)) {
231 qDrawShadePanel(p, frame->rect, frame->palette, frame->state & State_Sunken,
234 qDrawPlainRect(p, frame->rect, frame->palette.windowText().color(), frame->lineWidth);
238#if QT_CONFIG(toolbar)
239 case PE_PanelMenuBar:
240 if (widget && qobject_cast<QToolBar *>(widget->parentWidget()))
242 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)){
243 qDrawShadePanel(p, frame->rect, frame->palette,
false, frame->lineWidth,
244 &frame->palette.brush(QPalette::Button));
247 else if (
const QStyleOptionToolBar *frame = qstyleoption_cast<
const QStyleOptionToolBar *>(opt)){
248 qDrawShadePanel(p, frame->rect, frame->palette,
false, frame->lineWidth,
249 &frame->palette.brush(QPalette::Button));
255 case PE_PanelToolBar:
258#if QT_CONFIG(progressbar)
259 case PE_IndicatorProgressChunk:
261 bool vertical =
false;
262 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt))
263 vertical = !(pb->state & QStyle::State_Horizontal);
265 p->fillRect(opt->rect.x(), opt->rect.y() + 3, opt->rect.width() -2, opt->rect.height() - 6,
266 opt->palette.brush(QPalette::Highlight));
268 p->fillRect(opt->rect.x() + 2, opt->rect.y(), opt->rect.width() -6, opt->rect.height() - 2,
269 opt->palette.brush(QPalette::Highlight));
274 case PE_IndicatorBranch: {
275 static const int decoration_size = 9;
276 int mid_h = opt->rect.x() + opt->rect.width() / 2;
277 int mid_v = opt->rect.y() + opt->rect.height() / 2;
282 if (opt->state & State_Children) {
283 int delta = decoration_size / 2;
288 p->drawLine(bef_h + 2, bef_v + 4, bef_h + 6, bef_v + 4);
289 if (!(opt->state & State_Open))
290 p->drawLine(bef_h + 4, bef_v + 2, bef_h + 4, bef_v + 6);
291 QPen oldPen = p->pen();
292 p->setPen(opt->palette.dark().color());
293 p->drawRect(bef_h, bef_v, decoration_size - 1, decoration_size - 1);
296 QBrush brush(opt->palette.dark().color(), Qt::Dense4Pattern);
297 if (opt->state & State_Item) {
298 if (opt->direction == Qt::RightToLeft)
299 p->fillRect(opt->rect.left(), mid_v, bef_h - opt->rect.left(), 1, brush);
301 p->fillRect(aft_h, mid_v, opt->rect.right() - aft_h + 1, 1, brush);
303 if (opt->state & State_Sibling)
304 p->fillRect(mid_h, aft_v, 1, opt->rect.bottom() - aft_v + 1, brush);
305 if (opt->state & (State_Open | State_Children | State_Item | State_Sibling))
306 p->fillRect(mid_h, opt->rect.y(), 1, bef_v - opt->rect.y(), brush);
308 case PE_FrameStatusBarItem:
309 qDrawShadeRect(p, opt->rect, opt->palette,
true, 1, 0,
nullptr);
311 case PE_IndicatorHeaderArrow:
312 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
313 QPainterStateGuard psg(p, QPainterStateGuard::InitialState::NoSave);
314 if (header->sortIndicator & QStyleOptionHeader::SortUp) {
316 p->setPen(QPen(opt->palette.light(), 0));
317 p->drawLine(opt->rect.x() + opt->rect.width(), opt->rect.y(),
318 opt->rect.x() + opt->rect.width() / 2, opt->rect.y() + opt->rect.height());
319 p->setPen(QPen(opt->palette.dark(), 0));
320 const QPoint points[] = {
321 QPoint(opt->rect.x() + opt->rect.width() / 2, opt->rect.y() + opt->rect.height()),
322 QPoint(opt->rect.x(), opt->rect.y()),
323 QPoint(opt->rect.x() + opt->rect.width(), opt->rect.y()),
325 p->drawPolyline(points,
sizeof points /
sizeof *points);
326 }
else if (header->sortIndicator & QStyleOptionHeader::SortDown) {
328 p->setPen(QPen(opt->palette.light(), 0));
329 const QPoint points[] = {
330 QPoint(opt->rect.x(), opt->rect.y() + opt->rect.height()),
331 QPoint(opt->rect.x() + opt->rect.width(), opt->rect.y() + opt->rect.height()),
332 QPoint(opt->rect.x() + opt->rect.width() / 2, opt->rect.y()),
334 p->drawPolyline(points,
sizeof points /
sizeof *points);
335 p->setPen(QPen(opt->palette.dark(), 0));
336 p->drawLine(opt->rect.x(), opt->rect.y() + opt->rect.height(),
337 opt->rect.x() + opt->rect.width() / 2, opt->rect.y());
342 case PE_FrameTabBarBase:
343 if (
const QStyleOptionTabBarBase *tbb
344 = qstyleoption_cast<
const QStyleOptionTabBarBase *>(opt)) {
345 QPainterStateGuard psg(p);
346 switch (tbb->shape) {
347 case QTabBar::RoundedNorth:
348 case QTabBar::TriangularNorth:
349 p->setPen(QPen(tbb->palette.light(), 0));
350 p->drawLine(tbb->rect.topLeft(), tbb->rect.topRight());
352 case QTabBar::RoundedWest:
353 case QTabBar::TriangularWest:
354 p->setPen(QPen(tbb->palette.light(), 0));
355 p->drawLine(tbb->rect.topLeft(), tbb->rect.bottomLeft());
357 case QTabBar::RoundedSouth:
358 case QTabBar::TriangularSouth:
359 p->setPen(QPen(tbb->palette.shadow(), 0));
360 p->drawLine(tbb->rect.left(), tbb->rect.bottom(),
361 tbb->rect.right(), tbb->rect.bottom());
362 p->setPen(QPen(tbb->palette.dark(), 0));
363 p->drawLine(tbb->rect.left(), tbb->rect.bottom() - 1,
364 tbb->rect.right() - 1, tbb->rect.bottom() - 1);
366 case QTabBar::RoundedEast:
367 case QTabBar::TriangularEast:
368 p->setPen(QPen(tbb->palette.dark(), 0));
369 p->drawLine(tbb->rect.topRight(), tbb->rect.bottomRight());
374 case PE_IndicatorTabClose: {
375 if (d->tabBarcloseButtonIcon.isNull())
376 d->tabBarcloseButtonIcon = proxy()->standardIcon(QStyle::SP_TabCloseButton, opt, widget);
378 const int size = proxy()->pixelMetric(QStyle::PM_SmallIconSize, opt, widget);
379 QIcon::Mode mode = opt->state & State_Enabled ?
380 (opt->state & State_Raised ? QIcon::Active : QIcon::Normal)
382 if (!opt->state.testAnyFlags(State_Raised | State_Sunken | State_Selected))
383 mode = QIcon::Disabled;
385 QIcon::State state = opt->state & State_Sunken ? QIcon::On : QIcon::Off;
386 QPixmap pixmap = d->tabBarcloseButtonIcon.pixmap(QSize(size, size), QStyleHelper::getDpr(p), mode, state);
387 proxy()->drawItemPixmap(p, opt->rect, Qt::AlignCenter, pixmap);
393 case PE_FrameTabWidget:
395 qDrawWinPanel(p, opt->rect, opt->palette,
false,
nullptr);
397 case PE_FrameLineEdit:
398 proxy()->drawPrimitive(PE_Frame, opt, p, widget);
400#if QT_CONFIG(groupbox)
401 case PE_FrameGroupBox:
402 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
403 if (frame->features & QStyleOptionFrame::Flat) {
404 QRect fr = frame->rect;
405 QPoint p1(fr.x(), fr.y() + 1);
406 QPoint p2(fr.x() + fr.width(), p1.y());
407 qDrawShadeLine(p, p1, p2, frame->palette,
true,
408 frame->lineWidth, frame->midLineWidth);
410 qDrawShadeRect(p, frame->rect.x(), frame->rect.y(), frame->rect.width(),
411 frame->rect.height(), frame->palette,
true,
412 frame->lineWidth, frame->midLineWidth);
417#if QT_CONFIG(dockwidget)
418 case PE_FrameDockWidget:
419 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
420 int lw = frame->lineWidth;
422 lw = proxy()->pixelMetric(PM_DockWidgetFrameWidth, opt, widget);
424 qDrawShadePanel(p, frame->rect, frame->palette,
false, lw);
428#if QT_CONFIG(toolbar)
429 case PE_IndicatorToolBarHandle: {
430 QPainterStateGuard psg(p);
431 p->translate(opt->rect.x(), opt->rect.y());
432 if (opt->state & State_Horizontal) {
433 int x = opt->rect.width() / 3;
434 if (opt->direction == Qt::RightToLeft)
436 if (opt->rect.height() > 4) {
437 qDrawShadePanel(p, x, 2, 3, opt->rect.height() - 4,
438 opt->palette,
false, 1,
nullptr);
439 qDrawShadePanel(p, x+3, 2, 3, opt->rect.height() - 4,
440 opt->palette,
false, 1,
nullptr);
443 if (opt->rect.width() > 4) {
444 int y = opt->rect.height() / 3;
445 qDrawShadePanel(p, 2, y, opt->rect.width() - 4, 3,
446 opt->palette,
false, 1,
nullptr);
447 qDrawShadePanel(p, 2, y+3, opt->rect.width() - 4, 3,
448 opt->palette,
false, 1,
nullptr);
453 case PE_IndicatorToolBarSeparator:
456 if (opt->state & State_Horizontal) {
457 p1 = QPoint(opt->rect.width()/2, 0);
458 p2 = QPoint(p1.x(), opt->rect.height());
460 p1 = QPoint(0, opt->rect.height()/2);
461 p2 = QPoint(opt->rect.width(), p1.y());
463 qDrawShadeLine(p, p1, p2, opt->palette, 1, 1, 0);
467#if QT_CONFIG(spinbox)
468 case PE_IndicatorSpinPlus:
469 case PE_IndicatorSpinMinus: {
471 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget);
472 QRect br = r.adjusted(fw, fw, -fw, -fw);
477 QPainterStateGuard psg(p);
478 const qreal devicePixelRatio = QStyleHelper::getDpr(p);
479 if (!qFuzzyCompare(devicePixelRatio, qreal(1))) {
480 const qreal inverseScale = qreal(1) / devicePixelRatio;
481 p->scale(inverseScale, inverseScale);
482 x = qRound(devicePixelRatio * x);
483 y = qRound(devicePixelRatio * y);
484 w = qRound(devicePixelRatio * w);
485 h = qRound(devicePixelRatio * h);
486 p->translate(0.5, 0.5);
488 int len = std::min(w, h);
491 int step = (len + 4) / 5;
494 const int step2 = step / 2;
495 QPoint center(x + w / 2, y + h / 2);
496 if (opt->state & State_Sunken) {
497 center += QPoint(proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget),
498 proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget));
500 p->translate(center);
501 p->fillRect(-len / 2, -step2, len, step, opt->palette.buttonText());
502 if (pe == PE_IndicatorSpinPlus)
503 p->fillRect(-step2, -len / 2, step, len, opt->palette.buttonText());
505 case PE_IndicatorSpinUp:
506 case PE_IndicatorSpinDown: {
508 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget);
514 QPainterStateGuard psg(p);
515 const qreal devicePixelRatio = QStyleHelper::getDpr(p);
516 if (!qFuzzyCompare(devicePixelRatio, qreal(1))) {
517 const qreal inverseScale = qreal(1) / devicePixelRatio;
518 p->scale(inverseScale, inverseScale);
519 x = qRound(devicePixelRatio * x);
520 y = qRound(devicePixelRatio * y);
521 w = qRound(devicePixelRatio * w);
522 h = qRound(devicePixelRatio * h);
523 p->translate(0.5, 0.5);
533 int sx = x + w / 2 - sw / 2;
534 int sy = y + h / 2 - sh / 2;
536 if (pe == PE_IndicatorSpinUp && fw)
541 if (opt->state & State_Sunken) {
542 bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget);
543 bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget);
545 p->translate(sx + bsx, sy + bsy);
546 p->setPen(opt->palette.buttonText().color());
547 p->setBrush(opt->palette.buttonText());
548 if (pe == PE_IndicatorSpinDown) {
549 const QPoint points[] = { QPoint(0, 1), QPoint(sw-1, 1), QPoint(sh-2, sh-1) };
550 p->drawPolygon(points,
sizeof points /
sizeof *points);
552 const QPoint points[] = { QPoint(0, sh-1), QPoint(sw-1, sh-1), QPoint(sh-2, 1) };
553 p->drawPolygon(points,
sizeof points /
sizeof *points);
557 case PE_PanelTipLabel: {
558 const QBrush brush(opt->palette.toolTipBase());
559 qDrawPlainRect(p, opt->rect, opt->palette.toolTipText().color(), 1, &brush);
563 case PE_IndicatorTabTear:
564 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
565 bool rtl = tab->direction == Qt::RightToLeft;
566 const bool horizontal = tab->rect.height() > tab->rect.width();
567 const bool isSelected = tab->state.testFlag(State_Selected);
568 const int margin = 4;
572 QRect rect = tab->rect.adjusted(rtl ? margin : 0, 0, rtl ? 1 : -margin, 0);
573 rect.setTop(rect.top() + (isSelected ? 1 : 3));
574 rect.setBottom(rect.bottom() - (isSelected ? 0 : 2));
576 path.moveTo(QPoint(rtl ? rect.right() : rect.left(), rect.top()));
578 for (
int jags = 1; jags <= count; ++jags, rtl = !rtl)
579 path.lineTo(QPoint(rtl ? rect.left() : rect.right(), rect.top() + jags * rect.height()/count));
581 QRect rect = tab->rect.adjusted(0, 0, 0, -margin);
582 rect.setLeft(rect.left() + (isSelected ? 1 : 3));
583 rect.setRight(rect.right() - (isSelected ? 0 : 2));
585 path.moveTo(QPoint(rect.left(), rect.top()));
587 for (
int jags = 1; jags <= count; ++jags, rtl = !rtl)
588 path.lineTo(QPoint(rect.left() + jags * rect.width()/count, rtl ? rect.top() : rect.bottom()));
591 p->setPen(QPen(tab->palette.dark(), qreal(.8)));
592 p->setBrush(tab->palette.window());
593 p->setRenderHint(QPainter::Antialiasing);
598#if QT_CONFIG(lineedit)
599 case PE_PanelLineEdit:
600 if (
const QStyleOptionFrame *panel = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
601 p->fillRect(panel->rect.adjusted(panel->lineWidth, panel->lineWidth, -panel->lineWidth, -panel->lineWidth),
602 panel->palette.brush(QPalette::Base));
604 if (panel->lineWidth > 0)
605 proxy()->drawPrimitive(PE_FrameLineEdit, panel, p, widget);
609#if QT_CONFIG(columnview)
610 case PE_IndicatorColumnViewArrow: {
611 if (
const QStyleOptionViewItem *viewOpt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
612 bool reverse = (viewOpt->direction == Qt::RightToLeft);
613 QPainterStateGuard psg(p);
615 int x = viewOpt->rect.x() + 1;
616 int offset = (viewOpt->rect.height() / 3);
617 int height = (viewOpt->rect.height()) - offset * 2;
620 int x2 = x + height - 1;
622 x = viewOpt->rect.x() + viewOpt->rect.width() - 1;
625 path.moveTo(x, viewOpt->rect.y() + offset);
626 path.lineTo(x, viewOpt->rect.y() + offset + height);
627 path.lineTo(x2, viewOpt->rect.y() + offset+height/2);
629 if (viewOpt->state & QStyle::State_Selected ) {
630 if (viewOpt->showDecorationSelected) {
631 QColor color = viewOpt->palette.color(QPalette::Active, QPalette::HighlightedText);
635 QColor color = viewOpt->palette.color(QPalette::Active, QPalette::WindowText);
641 QColor color = viewOpt->palette.color(QPalette::Active, QPalette::Mid);
648 if (!(viewOpt->state & QStyle::State_Selected)) {
650 lines.moveTo(x, viewOpt->rect.y() + offset);
651 lines.lineTo(x, viewOpt->rect.y() + offset + height);
652 lines.moveTo(x, viewOpt->rect.y() + offset);
653 lines.lineTo(x2, viewOpt->rect.y() + offset+height/2);
654 QColor color = viewOpt->palette.color(QPalette::Active, QPalette::Dark);
661 case PE_IndicatorItemViewItemDrop: {
662 QRect rect = opt->rect;
663 if (opt->rect.height() == 0)
664 p->drawLine(rect.topLeft(), rect.topRight());
668#if QT_CONFIG(itemviews)
669 case PE_PanelItemViewRow:
670 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
671 QPalette::ColorGroup cg = (widget ? widget->isEnabled() : (vopt->state & QStyle::State_Enabled))
672 ? QPalette::Normal : QPalette::Disabled;
673 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))
674 cg = QPalette::Inactive;
676 if ((vopt->state & QStyle::State_Selected) && vopt->showDecorationSelected)
677 p->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::Highlight));
678 else if (vopt->features & QStyleOptionViewItem::Alternate)
679 p->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::AlternateBase));
682 case PE_PanelItemViewItem:
683 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
684 QPalette::ColorGroup cg = (widget ? widget->isEnabled() : (vopt->state & QStyle::State_Enabled))
685 ? QPalette::Normal : QPalette::Disabled;
686 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))
687 cg = QPalette::Inactive;
689 if (vopt->showDecorationSelected && (vopt->state & QStyle::State_Selected)) {
690 p->fillRect(vopt->rect, vopt->palette.brush(cg, QPalette::Highlight));
692 if (vopt->backgroundBrush.style() != Qt::NoBrush) {
693 QPainterStateGuard psg(p);
694 p->setBrushOrigin(vopt->rect.topLeft());
695 p->fillRect(vopt->rect, vopt->backgroundBrush);
698 if (vopt->state & QStyle::State_Selected) {
699 QRect textRect = subElementRect(QStyle::SE_ItemViewItemText, opt, widget);
700 p->fillRect(textRect, vopt->palette.brush(cg, QPalette::Highlight));
706 case PE_PanelScrollAreaCorner: {
707 const QBrush brush(opt->palette.brush(QPalette::Window));
708 p->fillRect(opt->rect, brush);
710 case PE_IndicatorArrowUp:
711 case PE_IndicatorArrowDown:
712 case PE_IndicatorArrowRight:
713 case PE_IndicatorArrowLeft:
715 const QRect &r = opt->rect;
716 if (r.width() <= 1 || r.height() <= 1)
718 int size = qMin(r.height(), r.width());
720 const qreal dpr = QStyleHelper::getDpr(p);
721 const QString pixmapName = QStyleHelper::uniqueName(
"$qt_ia-"_L1
722 % QLatin1StringView(metaObject()->className())
723 % HexString<uint>(pe),
724 opt, QSize(size, size), dpr);
725 if (!QPixmapCache::find(pixmapName, &pixmap)) {
727 const int border = 1 * dpr;
728 const int sizeDpr = size * dpr;
729 int width = sizeDpr - 2 * border - 1;
730 int height = width / 2;
731 const int add = ((width & 1) == 1);
732 if (pe == PE_IndicatorArrowRight || pe == PE_IndicatorArrowLeft)
733 std::swap(width, height);
734 pixmap = styleCachePixmap(QSize(sizeDpr, sizeDpr), 1);
736 std::array<QPointF, 4> poly;
738 case PE_IndicatorArrowUp:
739 poly = {QPointF(0, height), QPointF(width, height),
740 QPointF(width / 2 + add, 0), QPointF(width / 2, 0)};
742 case PE_IndicatorArrowDown:
743 poly = {QPointF(0, 0), QPointF(width, 0),
744 QPointF(width / 2 + add, height), QPointF(width / 2, height)};
746 case PE_IndicatorArrowRight:
747 poly = {QPointF(0, 0), QPointF(0, height),
748 QPointF(width, height / 2 + add), QPointF(width, height / 2)};
750 case PE_IndicatorArrowLeft:
751 poly = {QPointF(width, 0), QPointF(width, height),
752 QPointF(0, height / 2 + add), QPointF(0, height / 2)};
758 QPainter imagePainter(&pixmap);
759 imagePainter.translate((sizeDpr - width) / 2, (sizeDpr - height) / 2);
760 if (opt->state & State_Sunken) {
761 const auto bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget);
762 const auto bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget);
763 imagePainter.translate(bsx, bsy);
765 imagePainter.setPen(opt->palette.buttonText().color());
766 imagePainter.setBrush(opt->palette.buttonText());
768 if (!(opt->state & State_Enabled)) {
769 const int ofs = qRound(1 * dpr);
770 imagePainter.translate(ofs, ofs);
771 imagePainter.setBrush(opt->palette.light());
772 imagePainter.setPen(opt->palette.light().color());
773 imagePainter.drawPolygon(poly.data(),
int(poly.size()));
774 imagePainter.drawPoints(poly.data(),
int(poly.size()));
775 imagePainter.translate(-ofs, -ofs);
776 imagePainter.setBrush(opt->palette.mid());
777 imagePainter.setPen(opt->palette.mid().color());
779 imagePainter.drawPolygon(poly.data(),
int(poly.size()));
781 imagePainter.drawPoints(poly.data(),
int(poly.size()));
783 pixmap.setDevicePixelRatio(dpr);
784 QPixmapCache::insert(pixmapName, pixmap);
786 int xOffset = r.x() + (r.width() - size)/2;
787 int yOffset = r.y() + (r.height() - size)/2;
788 p->drawPixmap(xOffset, yOffset, pixmap);
1288void QCommonStyle::drawControl(ControlElement element,
const QStyleOption *opt,
1289 QPainter *p,
const QWidget *widget)
const
1291 Q_D(
const QCommonStyle);
1295 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
1296 proxy()->drawControl(CE_PushButtonBevel, btn, p, widget);
1297 QStyleOptionButton subopt = *btn;
1298 subopt.rect = subElementRect(SE_PushButtonContents, btn, widget);
1299 proxy()->drawControl(CE_PushButtonLabel, &subopt, p, widget);
1300 if (btn->state & State_HasFocus) {
1301 QStyleOptionFocusRect fropt;
1302 fropt.QStyleOption::operator=(*btn);
1303 fropt.rect = subElementRect(SE_PushButtonFocusRect, btn, widget);
1304 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
1308 case CE_PushButtonBevel:
1309 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
1310 QRect br = btn->rect;
1311 int dbi = proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
1312 if (btn->features & QStyleOptionButton::DefaultButton)
1313 proxy()->drawPrimitive(PE_FrameDefaultButton, opt, p, widget);
1314 if (btn->features & QStyleOptionButton::AutoDefaultButton)
1315 br.setCoords(br.left() + dbi, br.top() + dbi, br.right() - dbi, br.bottom() - dbi);
1316 if (!(btn->features & (QStyleOptionButton::Flat | QStyleOptionButton::CommandLinkButton))
1317 || btn->state & (State_Sunken | State_On)
1318 || (btn->features & QStyleOptionButton::CommandLinkButton && btn->state & State_MouseOver)) {
1319 QStyleOptionButton tmpBtn = *btn;
1321 proxy()->drawPrimitive(PE_PanelButtonCommand, &tmpBtn, p, widget);
1323 if (btn->features & QStyleOptionButton::HasMenu) {
1324 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, btn, widget);
1325 QRect ir = btn->rect;
1326 QStyleOptionButton newBtn = *btn;
1327 newBtn.rect = QRect(ir.right() - mbi - 2, ir.height()/2 - mbi/2 + 3, mbi - 6, mbi - 6);
1328 newBtn.rect = visualRect(btn->direction, br, newBtn.rect);
1329 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, p, widget);
1333 case CE_PushButtonLabel:
1334 if (
const QStyleOptionButton *button = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
1335 QRect textRect = button->rect;
1336 int tf = Qt::AlignVCenter | Qt::TextShowMnemonic;
1337 if (!proxy()->styleHint(SH_UnderlineShortcut, button, widget))
1338 tf |= Qt::TextHideMnemonic;
1340 if (button->features & QStyleOptionButton::HasMenu) {
1341 int indicatorSize = proxy()->pixelMetric(PM_MenuButtonIndicator, button, widget);
1342 if (button->direction == Qt::LeftToRight)
1343 textRect = textRect.adjusted(0, 0, -indicatorSize, 0);
1345 textRect = textRect.adjusted(indicatorSize, 0, 0, 0);
1348 if (!button->icon.isNull()) {
1350 QIcon::Mode mode = button->state & State_Enabled ? QIcon::Normal : QIcon::Disabled;
1351 if (mode == QIcon::Normal && button->state & State_HasFocus)
1352 mode = QIcon::Active;
1353 QIcon::State state = QIcon::Off;
1354 if (button->state & State_On)
1357 QPixmap pixmap = button->icon.pixmap(button->iconSize, QStyleHelper::getDpr(p), mode, state);
1358 int pixmapWidth = pixmap.width() / pixmap.devicePixelRatio();
1359 int pixmapHeight = pixmap.height() / pixmap.devicePixelRatio();
1360 int labelWidth = pixmapWidth;
1361 int labelHeight = pixmapHeight;
1362 int iconSpacing = 4;
1363 if (!button->text.isEmpty()) {
1364 int textWidth = button->fontMetrics.boundingRect(opt->rect, tf, button->text).width();
1365 labelWidth += (textWidth + iconSpacing);
1368 QRect iconRect = QRect(textRect.x() + (textRect.width() - labelWidth) / 2,
1369 textRect.y() + (textRect.height() - labelHeight) / 2,
1370 pixmapWidth, pixmapHeight);
1372 iconRect = visualRect(button->direction, textRect, iconRect);
1374 if (button->direction == Qt::RightToLeft)
1375 textRect.setRight(iconRect.left() - iconSpacing / 2);
1377 textRect.setLeft(iconRect.left() + iconRect.width() + iconSpacing / 2);
1380 if (p->layoutDirection() == button->direction)
1381 tf |= Qt::AlignLeft;
1383 tf |= Qt::AlignRight;
1385 if (button->state & (State_On | State_Sunken))
1386 iconRect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget),
1387 proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget));
1388 p->drawPixmap(iconRect, pixmap);
1390 tf |= Qt::AlignHCenter;
1392 if (button->state & (State_On | State_Sunken))
1393 textRect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget),
1394 proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget));
1396 proxy()->drawItemText(p, textRect, tf, button->palette, (button->state & State_Enabled),
1397 button->text, QPalette::ButtonText);
1400 case CE_RadioButton:
1402 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
1403 bool isRadio = (element == CE_RadioButton);
1404 QStyleOptionButton subopt = *btn;
1405 subopt.rect = subElementRect(isRadio ? SE_RadioButtonIndicator
1406 : SE_CheckBoxIndicator, btn, widget);
1407 proxy()->drawPrimitive(isRadio ? PE_IndicatorRadioButton : PE_IndicatorCheckBox,
1408 &subopt, p, widget);
1409 subopt.rect = subElementRect(isRadio ? SE_RadioButtonContents
1410 : SE_CheckBoxContents, btn, widget);
1411 proxy()->drawControl(isRadio ? CE_RadioButtonLabel : CE_CheckBoxLabel, &subopt, p, widget);
1412 if (btn->state & State_HasFocus) {
1413 QStyleOptionFocusRect fropt;
1414 fropt.QStyleOption::operator=(*btn);
1415 fropt.rect = subElementRect(isRadio ? SE_RadioButtonFocusRect
1416 : SE_CheckBoxFocusRect, btn, widget);
1417 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
1421 case CE_RadioButtonLabel:
1422 case CE_CheckBoxLabel:
1423 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
1424 int alignment = visualAlignment(btn->direction, Qt::AlignLeft | Qt::AlignVCenter);
1426 if (!proxy()->styleHint(SH_UnderlineShortcut, btn, widget))
1427 alignment |= Qt::TextHideMnemonic;
1428 QRect textRect = btn->rect;
1429 if (!btn->icon.isNull()) {
1430 const auto pix = btn->icon.pixmap(btn->iconSize, QStyleHelper::getDpr(p),
1431 btn->state & State_Enabled ? QIcon::Normal : QIcon::Disabled);
1432 proxy()->drawItemPixmap(p, btn->rect, alignment, pix);
1433 if (btn->direction == Qt::RightToLeft)
1434 textRect.setRight(textRect.right() - btn->iconSize.width() - 4);
1436 textRect.setLeft(textRect.left() + btn->iconSize.width() + 4);
1438 if (!btn->text.isEmpty()){
1439 proxy()->drawItemText(p, textRect, alignment | Qt::TextShowMnemonic,
1440 btn->palette, btn->state & State_Enabled, btn->text, QPalette::WindowText);
1445 case CE_MenuScroller: {
1446 QStyleOption arrowOpt = *opt;
1447 arrowOpt.state |= State_Enabled;
1448 proxy()->drawPrimitive(((opt->state & State_DownArrow) ? PE_IndicatorArrowDown : PE_IndicatorArrowUp),
1449 &arrowOpt, p, widget);
1451 case CE_MenuTearoff:
1452 if (opt->state & State_Selected)
1453 p->fillRect(opt->rect, opt->palette.brush(QPalette::Highlight));
1455 p->fillRect(opt->rect, opt->palette.brush(QPalette::Button));
1456 p->setPen(QPen(opt->palette.dark().color(), 1, Qt::DashLine));
1457 p->drawLine(opt->rect.x() + 2, opt->rect.y() + opt->rect.height() / 2 - 1,
1458 opt->rect.x() + opt->rect.width() - 4,
1459 opt->rect.y() + opt->rect.height() / 2 - 1);
1460 p->setPen(QPen(opt->palette.light().color(), 1, Qt::DashLine));
1461 p->drawLine(opt->rect.x() + 2, opt->rect.y() + opt->rect.height() / 2,
1462 opt->rect.x() + opt->rect.width() - 4, opt->rect.y() + opt->rect.height() / 2);
1465#if QT_CONFIG(menubar)
1466 case CE_MenuBarItem:
1467 if (
const QStyleOptionMenuItem *mbi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
1468 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic | Qt::TextDontClip
1469 | Qt::TextSingleLine;
1470 if (!proxy()->styleHint(SH_UnderlineShortcut, mbi, widget))
1471 alignment |= Qt::TextHideMnemonic;
1472 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
1473 QPixmap pix = mbi->icon.pixmap(QSize(iconExtent, iconExtent), QStyleHelper::getDpr(p), (mbi->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled);
1475 proxy()->drawItemPixmap(p,mbi->rect, alignment, pix);
1477 proxy()->drawItemText(p, mbi->rect, alignment, mbi->palette, mbi->state & State_Enabled,
1478 mbi->text, QPalette::ButtonText);
1481 case CE_MenuBarEmptyArea:
1482 if (widget && !widget->testAttribute(Qt::WA_NoSystemBackground))
1483 p->eraseRect(opt->rect);
1486#if QT_CONFIG(progressbar)
1487 case CE_ProgressBar:
1488 if (
const QStyleOptionProgressBar *pb
1489 = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
1490 QStyleOptionProgressBar subopt = *pb;
1491 subopt.rect = subElementRect(SE_ProgressBarGroove, pb, widget);
1492 proxy()->drawControl(CE_ProgressBarGroove, &subopt, p, widget);
1493 subopt.rect = subElementRect(SE_ProgressBarContents, pb, widget);
1494 proxy()->drawControl(CE_ProgressBarContents, &subopt, p, widget);
1495 if (pb->textVisible) {
1496 subopt.rect = subElementRect(SE_ProgressBarLabel, pb, widget);
1497 proxy()->drawControl(CE_ProgressBarLabel, &subopt, p, widget);
1501 case CE_ProgressBarGroove:
1502 if (opt->rect.isValid())
1503 qDrawShadePanel(p, opt->rect, opt->palette,
true, 1,
1504 &opt->palette.brush(QPalette::Window));
1506 case CE_ProgressBarLabel:
1507 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
1508 const bool vertical = !(pb->state & QStyle::State_Horizontal);
1510 QPalette::ColorRole textRole = QPalette::NoRole;
1511 if ((pb->textAlignment & Qt::AlignCenter) && pb->textVisible
1512 && ((qint64(pb->progress) - qint64(pb->minimum)) * 2 >= (qint64(pb->maximum) - qint64(pb->minimum)))) {
1513 textRole = QPalette::HighlightedText;
1515 QRect shadowRect(pb->rect);
1516 shadowRect.translate(1,1);
1517 QColor shadowColor = (pb->palette.color(textRole).value() <= 128)
1518 ? QColor(255,255,255,160) : QColor(0,0,0,160);
1519 QPalette shadowPalette = pb->palette;
1520 shadowPalette.setColor(textRole, shadowColor);
1521 proxy()->drawItemText(p, shadowRect, Qt::AlignCenter | Qt::TextSingleLine, shadowPalette,
1522 pb->state & State_Enabled, pb->text, textRole);
1524 proxy()->drawItemText(p, pb->rect, Qt::AlignCenter | Qt::TextSingleLine, pb->palette,
1525 pb->state & State_Enabled, pb->text, textRole);
1529 case CE_ProgressBarContents:
1530 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
1532 QRect rect = pb->rect;
1533 const bool vertical = !(pb->state & QStyle::State_Horizontal);
1534 const bool inverted = pb->invertedAppearance;
1535 qint64 minimum = qint64(pb->minimum);
1536 qint64 maximum = qint64(pb->maximum);
1537 qint64 progress = qint64(pb->progress);
1542 rect = QRect(rect.y(), rect.x(), rect.height(), rect.width());
1544 m.translate(0, -(rect.height() + rect.y()*2));
1547 QPalette pal2 = pb->palette;
1549 if (pal2.highlight() == pal2.window())
1550 pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active,
1551 QPalette::Highlight));
1552 bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical);
1555 int w = rect.width();
1556 if (pb->minimum == 0 && pb->maximum == 0) {
1558 int x = (progress - minimum) % (w * 2);
1561 x = reverse ? rect.right() - x : x + rect.x();
1562 p->setPen(QPen(pal2.highlight().color(), 4));
1563 p->drawLine(x, rect.y(), x, rect.height());
1565 const int unit_width = proxy()->pixelMetric(PM_ProgressBarChunkWidth, pb, widget);
1571 u = ((rect.width() + unit_width) / unit_width);
1574 qint64 p_v = progress - minimum;
1575 qint64 t_s = (maximum - minimum) ? (maximum - minimum) : qint64(1);
1577 if (u > 0 && p_v >= INT_MAX / u && t_s >= u) {
1585 tnu = nu = p_v * u / t_s;
1587 if (nu * unit_width > w)
1595 int x0 = reverse ? rect.right() - ((unit_width > 1) ? unit_width : 0)
1598 QStyleOptionProgressBar pbBits = *pb;
1600 pbBits.palette = pal2;
1601 int myY = pbBits.rect.y();
1602 int myHeight = pbBits.rect.height();
1603 pbBits.state &= QStyle::State_Horizontal;
1604 for (
int i = 0; i < nu; ++i) {
1605 pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);
1606 pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();
1607 proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
1608 x += reverse ? -unit_width : unit_width;
1614 int pixels_left = w - (nu * unit_width);
1615 int offset = reverse ? x0 + x + unit_width-pixels_left : x0 + x;
1616 pbBits.rect.setRect(offset, myY, pixels_left, myHeight);
1617 pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();
1618 proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
1624 case CE_HeaderLabel:
1625 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
1626 QRect rect = header->rect;
1627 if (!header->icon.isNull()) {
1628 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
1630 = header->icon.pixmap(QSize(iconExtent, iconExtent), QStyleHelper::getDpr(p), (header->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled);
1631 int pixw = pixmap.width() / pixmap.devicePixelRatio();
1633 QRect aligned = alignedRect(header->direction, header->iconAlignment, pixmap.size() / pixmap.devicePixelRatio(), rect);
1634 QRect inter = aligned.intersected(rect);
1635 p->drawPixmap(inter.x(), inter.y(), pixmap,
1636 inter.x() - aligned.x(), inter.y() - aligned.y(),
1637 aligned.width() * pixmap.devicePixelRatio(),
1638 pixmap.height() * pixmap.devicePixelRatio());
1640 const int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget);
1641 if (header->direction == Qt::LeftToRight)
1642 rect.setLeft(rect.left() + pixw + margin);
1644 rect.setRight(rect.right() - pixw - margin);
1646 QFontMetrics fm(header->fontMetrics);
1647 if (header->state & QStyle::State_On) {
1648 QFont fnt = p->font();
1650 if (!(fnt.resolveMask() & QFont::WeightResolved)) {
1653 fm = QFontMetrics((p->font()));
1656 QString text = header->text;
1657 if (
const QStyleOptionHeaderV2 *headerV2 = qstyleoption_cast<
const QStyleOptionHeaderV2 *>(header)) {
1658 if (headerV2->textElideMode != Qt::ElideNone)
1659 text = fm.elidedText(header->text, headerV2->textElideMode, rect.width());
1661 proxy()->drawItemText(p, rect, header->textAlignment, header->palette,
1662 header->state.testFlag(State_Enabled), text, QPalette::ButtonText);
1665#if QT_CONFIG(toolbutton)
1666 case CE_ToolButtonLabel:
1667 if (
const QStyleOptionToolButton *toolbutton
1668 = qstyleoption_cast<
const QStyleOptionToolButton *>(opt)) {
1669 QRect rect = toolbutton->rect;
1672 if (toolbutton->state & (State_Sunken | State_On)) {
1673 shiftX = proxy()->pixelMetric(PM_ButtonShiftHorizontal, toolbutton, widget);
1674 shiftY = proxy()->pixelMetric(PM_ButtonShiftVertical, toolbutton, widget);
1677 bool hasArrow = toolbutton->features & QStyleOptionToolButton::Arrow;
1678 if (((!hasArrow && toolbutton->icon.isNull()) && !toolbutton->text.isEmpty())
1679 || toolbutton->toolButtonStyle == Qt::ToolButtonTextOnly) {
1680 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;
1681 if (!proxy()->styleHint(SH_UnderlineShortcut, opt, widget))
1682 alignment |= Qt::TextHideMnemonic;
1683 rect.translate(shiftX, shiftY);
1684 p->setFont(toolbutton->font);
1685 const QString text = d->toolButtonElideText(toolbutton, rect, alignment);
1686 proxy()->drawItemText(p, rect, alignment, toolbutton->palette,
1687 opt->state & State_Enabled, text,
1688 QPalette::ButtonText);
1691 QSize pmSize = toolbutton->iconSize;
1692 if (!toolbutton->icon.isNull()) {
1693 QIcon::State state = toolbutton->state & State_On ? QIcon::On : QIcon::Off;
1695 if (!(toolbutton->state & State_Enabled))
1696 mode = QIcon::Disabled;
1697 else if ((opt->state & State_MouseOver) && (opt->state & State_AutoRaise))
1698 mode = QIcon::Active;
1700 mode = QIcon::Normal;
1701 pm = toolbutton->icon.pixmap(toolbutton->rect.size().boundedTo(toolbutton->iconSize), QStyleHelper::getDpr(p),
1703 pmSize = pm.size() / pm.devicePixelRatio();
1706 if (toolbutton->toolButtonStyle != Qt::ToolButtonIconOnly) {
1707 p->setFont(toolbutton->font);
1710 int alignment = Qt::TextShowMnemonic;
1711 if (!proxy()->styleHint(SH_UnderlineShortcut, opt, widget))
1712 alignment |= Qt::TextHideMnemonic;
1714 if (toolbutton->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
1715 pr.setHeight(pmSize.height() + 4);
1716 tr.adjust(0, pr.height() - 1, 0, -1);
1717 pr.translate(shiftX, shiftY);
1719 proxy()->drawItemPixmap(p, pr, Qt::AlignCenter, pm);
1721 drawArrow(proxy(), toolbutton, pr, p, widget);
1723 alignment |= Qt::AlignCenter;
1725 pr.setWidth(pmSize.width() + 4);
1726 tr.adjust(pr.width(), 0, 0, 0);
1727 pr.translate(shiftX, shiftY);
1729 proxy()->drawItemPixmap(p, QStyle::visualRect(opt->direction, rect, pr), Qt::AlignCenter, pm);
1731 drawArrow(proxy(), toolbutton, pr, p, widget);
1733 alignment |= Qt::AlignLeft | Qt::AlignVCenter;
1735 tr.translate(shiftX, shiftY);
1736 const QString text = d->toolButtonElideText(toolbutton, tr, alignment);
1737 proxy()->drawItemText(p, QStyle::visualRect(opt->direction, rect, tr), alignment, toolbutton->palette,
1738 toolbutton->state & State_Enabled, text,
1739 QPalette::ButtonText);
1741 rect.translate(shiftX, shiftY);
1743 drawArrow(proxy(), toolbutton, rect, p, widget);
1745 proxy()->drawItemPixmap(p, rect, Qt::AlignCenter, pm);
1752#if QT_CONFIG(toolbox)
1754 if (
const QStyleOptionToolBox *tb = qstyleoption_cast<
const QStyleOptionToolBox *>(opt)) {
1755 proxy()->drawControl(CE_ToolBoxTabShape, tb, p, widget);
1756 proxy()->drawControl(CE_ToolBoxTabLabel, tb, p, widget);
1759 case CE_ToolBoxTabShape:
1760 if (
const QStyleOptionToolBox *tb = qstyleoption_cast<
const QStyleOptionToolBox *>(opt)) {
1761 p->setPen(tb->palette.mid().color().darker(150));
1762 int d = 20 + tb->rect.height() - 3;
1763 if (tb->direction != Qt::RightToLeft) {
1764 const QPoint points[] = {
1765 QPoint(-1, tb->rect.height() + 1),
1767 QPoint(tb->rect.width() - d, 1),
1768 QPoint(tb->rect.width() - 20, tb->rect.height() - 2),
1769 QPoint(tb->rect.width() - 1, tb->rect.height() - 2),
1770 QPoint(tb->rect.width() - 1, tb->rect.height() + 1),
1771 QPoint(-1, tb->rect.height() + 1),
1773 p->drawPolygon(points,
sizeof points /
sizeof *points);
1775 const QPoint points[] = {
1776 QPoint(tb->rect.width(), tb->rect.height() + 1),
1777 QPoint(tb->rect.width(), 1),
1779 QPoint(20 - 1, tb->rect.height() - 2),
1780 QPoint(0, tb->rect.height() - 2),
1781 QPoint(0, tb->rect.height() + 1),
1782 QPoint(tb->rect.width(), tb->rect.height() + 1),
1784 p->drawPolygon(points,
sizeof points /
sizeof *points);
1786 p->setPen(tb->palette.light().color());
1787 if (tb->direction != Qt::RightToLeft) {
1788 p->drawLine(0, 2, tb->rect.width() - d, 2);
1789 p->drawLine(tb->rect.width() - d - 1, 2, tb->rect.width() - 21, tb->rect.height() - 1);
1790 p->drawLine(tb->rect.width() - 20, tb->rect.height() - 1,
1791 tb->rect.width(), tb->rect.height() - 1);
1793 p->drawLine(tb->rect.width() - 1, 2, d - 1, 2);
1794 p->drawLine(d, 2, 20, tb->rect.height() - 1);
1795 p->drawLine(19, tb->rect.height() - 1,
1796 -1, tb->rect.height() - 1);
1798 p->setBrush(Qt::NoBrush);
1802#if QT_CONFIG(tabbar)
1804 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
1805 proxy()->drawControl(CE_TabBarTabShape, tab, p, widget);
1806 proxy()->drawControl(CE_TabBarTabLabel, tab, p, widget);
1809 case CE_TabBarTabShape:
1810 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
1811 QPainterStateGuard psg(p);
1812 QRect rect(tab->rect);
1813 bool selected = tab->state & State_Selected;
1814 bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
1815 int tabOverlap = onlyOne ? 0 : proxy()->pixelMetric(PM_TabBarTabOverlap, opt, widget);
1818 switch (tab->shape) {
1819 case QTabBar::TriangularNorth:
1820 rect.adjust(0, 0, 0, -tabOverlap);
1822 rect.adjust(1, 1, -1, 0);
1824 case QTabBar::TriangularSouth:
1825 rect.adjust(0, tabOverlap, 0, 0);
1827 rect.adjust(1, 0, -1, -1);
1829 case QTabBar::TriangularEast:
1830 rect.adjust(tabOverlap, 0, 0, 0);
1832 rect.adjust(0, 1, -1, -1);
1834 case QTabBar::TriangularWest:
1835 rect.adjust(0, 0, -tabOverlap, 0);
1837 rect.adjust(1, 1, 0, -1);
1844 p->setPen(QPen(tab->palette.windowText(), 0));
1846 p->setBrush(tab->palette.base());
1848 if (widget && widget->parentWidget())
1849 p->setBrush(widget->parentWidget()->palette().window());
1851 p->setBrush(tab->palette.window());
1857 switch (tab->shape) {
1858 case QTabBar::TriangularNorth:
1859 case QTabBar::TriangularSouth: {
1860 a.setPoint(0, 0, -1);
1861 a.setPoint(1, 0, 0);
1862 y = rect.height() - 2;
1864 a.setPoint(2, x++, y - 1);
1866 a.setPoint(3, x++, y++);
1867 a.setPoint(4, x, y);
1870 int right = rect.width() - 1;
1871 for (i = 0; i < 5; ++i)
1872 a.setPoint(9 - i, right - a.point(i).x(), a.point(i).y());
1873 if (tab->shape == QTabBar::TriangularNorth)
1874 for (i = 0; i < 10; ++i)
1875 a.setPoint(i, a.point(i).x(), rect.height() - 1 - a.point(i).y());
1877 a.translate(rect.left(), rect.top());
1878 p->setRenderHint(QPainter::Antialiasing);
1879 p->translate(0, 0.5);
1885 case QTabBar::TriangularEast:
1886 case QTabBar::TriangularWest: {
1887 a.setPoint(0, -1, 0);
1888 a.setPoint(1, 0, 0);
1889 x = rect.width() - 2;
1891 a.setPoint(2, x - 1, y++);
1893 a.setPoint(3, x++, y++);
1894 a.setPoint(4, x, y);
1896 int bottom = rect.height() - 1;
1897 for (i = 0; i < 5; ++i)
1898 a.setPoint(9 - i, a.point(i).x(), bottom - a.point(i).y());
1899 if (tab->shape == QTabBar::TriangularWest)
1900 for (i = 0; i < 10; ++i)
1901 a.setPoint(i, rect.width() - 1 - a.point(i).x(), a.point(i).y());
1902 a.translate(rect.left(), rect.top());
1903 p->setRenderHint(QPainter::Antialiasing);
1904 p->translate(0.5, 0);
1914 case CE_ToolBoxTabLabel:
1915 if (
const QStyleOptionToolBox *tb = qstyleoption_cast<
const QStyleOptionToolBox *>(opt)) {
1916 bool enabled = tb->state & State_Enabled;
1917 bool selected = tb->state & State_Selected;
1918 int iconExtent = proxy()->pixelMetric(QStyle::PM_SmallIconSize, tb, widget);
1919 QPixmap pm = tb->icon.pixmap(QSize(iconExtent, iconExtent), QStyleHelper::getDpr(p),
1920 enabled ? QIcon::Normal : QIcon::Disabled);
1922 QRect cr = subElementRect(QStyle::SE_ToolBoxTabContents, tb, widget);
1927 tr.adjust(4, 0, -8, 0);
1929 int iw = pm.width() / pm.devicePixelRatio() + 4;
1930 ih = pm.height()/ pm.devicePixelRatio();
1931 ir = QRect(cr.left() + 4, cr.top(), iw + 2, ih);
1932 tr = QRect(ir.right(), cr.top(), cr.width() - ir.right() - 4, cr.height());
1935 if (selected && proxy()->styleHint(QStyle::SH_ToolBox_SelectedPageTitleBold, tb, widget)) {
1941 QString txt = tb->fontMetrics.elidedText(tb->text, Qt::ElideRight, tr.width());
1944 p->drawPixmap(ir.left(), (tb->rect.height() - ih) / 2, pm);
1946 int alignment = Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic;
1947 if (!proxy()->styleHint(QStyle::SH_UnderlineShortcut, tb, widget))
1948 alignment |= Qt::TextHideMnemonic;
1949 proxy()->drawItemText(p, tr, alignment, tb->palette, enabled, txt, QPalette::ButtonText);
1951 if (!txt.isEmpty() && opt->state & State_HasFocus) {
1952 QStyleOptionFocusRect opt;
1954 opt.palette = tb->palette;
1955 opt.state = QStyle::State_None;
1956 proxy()->drawPrimitive(QStyle::PE_FrameFocusRect, &opt, p, widget);
1960 case CE_TabBarTabLabel:
1961 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
1962 QRect tr = tab->rect;
1963 bool verticalTabs = tab->shape == QTabBar::RoundedEast
1964 || tab->shape == QTabBar::RoundedWest
1965 || tab->shape == QTabBar::TriangularEast
1966 || tab->shape == QTabBar::TriangularWest;
1968 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;
1969 if (!proxy()->styleHint(SH_UnderlineShortcut, opt, widget))
1970 alignment |= Qt::TextHideMnemonic;
1972 QPainterStateGuard psg(p, QPainterStateGuard::InitialState::NoSave);
1975 int newX, newY, newRot;
1976 if (tab->shape == QTabBar::RoundedEast || tab->shape == QTabBar::TriangularEast) {
1977 newX = tr.width() + tr.x();
1982 newY = tr.y() + tr.height();
1985 QTransform m = QTransform::fromTranslate(newX, newY);
1987 p->setTransform(m,
true);
1990 d->tabLayout(tab, widget, &tr, &iconRect);
1993 if (tab->position != QStyleOptionTab::TabPosition::Moving)
1994 tr = proxy()->subElementRect(SE_TabBarTabText, opt, widget);
1996 if (!tab->icon.isNull()) {
1997 QPixmap tabIcon = tab->icon.pixmap(tab->iconSize, QStyleHelper::getDpr(p),
1998 (tab->state & State_Enabled) ? QIcon::Normal
2000 (tab->state & State_Selected) ? QIcon::On
2002 p->drawPixmap(iconRect.x(), iconRect.y(), tabIcon);
2005 proxy()->drawItemText(p, tr, alignment, tab->palette, tab->state & State_Enabled, tab->text,
2006 widget ? widget->foregroundRole() : QPalette::WindowText);
2010 if (tab->state & State_HasFocus) {
2011 const int OFFSET = 1 + pixelMetric(PM_DefaultFrameWidth, opt, widget);
2014 x1 = tab->rect.left();
2015 x2 = tab->rect.right() - 1;
2017 QStyleOptionFocusRect fropt;
2018 fropt.QStyleOption::operator=(*tab);
2019 fropt.rect.setRect(x1 + 1 + OFFSET, tab->rect.y() + OFFSET,
2020 x2 - x1 - 2*OFFSET, tab->rect.height() - 2*OFFSET);
2021 drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
2026#if QT_CONFIG(sizegrip)
2028 QPainterStateGuard psg(p);
2030 opt->rect.getRect(&x, &y, &w, &h);
2032 int sw = qMin(h, w);
2034 p->translate(0, h - w);
2036 p->translate(w - h, 0);
2043 if (
const QStyleOptionSizeGrip *sgOpt = qstyleoption_cast<
const QStyleOptionSizeGrip *>(opt))
2044 corner = sgOpt->corner;
2045 else if (opt->direction == Qt::RightToLeft)
2046 corner = Qt::BottomLeftCorner;
2048 corner = Qt::BottomRightCorner;
2050 if (corner == Qt::BottomLeftCorner) {
2052 for (
int i = 0; i < 4; ++i) {
2053 p->setPen(opt->palette.light().color());
2054 p->drawLine(x, sy - 1 , sx + 1, sw);
2055 p->setPen(opt->palette.dark().color());
2056 p->drawLine(x, sy, sx, sw);
2057 p->setPen(opt->palette.dark().color());
2058 p->drawLine(x, sy + 1, sx - 1, sw);
2062 }
else if (corner == Qt::BottomRightCorner) {
2063 for (
int i = 0; i < 4; ++i) {
2064 p->setPen(opt->palette.light().color());
2065 p->drawLine(sx - 1, sw, sw, sy - 1);
2066 p->setPen(opt->palette.dark().color());
2067 p->drawLine(sx, sw, sw, sy);
2068 p->setPen(opt->palette.dark().color());
2069 p->drawLine(sx + 1, sw, sw, sy + 1);
2073 }
else if (corner == Qt::TopRightCorner) {
2075 for (
int i = 0; i < 4; ++i) {
2076 p->setPen(opt->palette.light().color());
2077 p->drawLine(sx - 1, y, sw, sy + 1);
2078 p->setPen(opt->palette.dark().color());
2079 p->drawLine(sx, y, sw, sy);
2080 p->setPen(opt->palette.dark().color());
2081 p->drawLine(sx + 1, y, sw, sy - 1);
2085 }
else if (corner == Qt::TopLeftCorner) {
2086 for (
int i = 0; i < 4; ++i) {
2087 p->setPen(opt->palette.light().color());
2088 p->drawLine(x, sy - 1, sx - 1, y);
2089 p->setPen(opt->palette.dark().color());
2090 p->drawLine(x, sy, sx, y);
2091 p->setPen(opt->palette.dark().color());
2092 p->drawLine(x, sy + 1, sx + 1, y);
2099#if QT_CONFIG(rubberband)
2100 case CE_RubberBand: {
2101 if (
const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<
const QStyleOptionRubberBand *>(opt)) {
2102 QPixmap tiledPixmap(16, 16);
2103 QPainter pixmapPainter(&tiledPixmap);
2104 pixmapPainter.setPen(Qt::NoPen);
2105 pixmapPainter.setBrush(Qt::Dense4Pattern);
2106 pixmapPainter.setBackground(QBrush(opt->palette.base()));
2107 pixmapPainter.setBackgroundMode(Qt::OpaqueMode);
2108 pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height());
2109 pixmapPainter.end();
2111 tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage());
2113 QPainterStateGuard psg(p);
2114 QRect r = opt->rect;
2115 QStyleHintReturnMask mask;
2116 if (proxy()->styleHint(QStyle::SH_RubberBand_Mask, opt, widget, &mask))
2117 p->setClipRegion(mask.region);
2118 p->drawTiledPixmap(r.x(), r.y(), r.width(), r.height(), tiledPixmap);
2119 p->setPen(opt->palette.color(QPalette::Active, QPalette::WindowText));
2120 p->setBrush(Qt::NoBrush);
2121 p->drawRect(r.adjusted(0, 0, -1, -1));
2122 if (rbOpt->shape == QRubberBand::Rectangle)
2123 p->drawRect(r.adjusted(3, 3, -4, -4));
2127#if QT_CONFIG(dockwidget)
2128 case CE_DockWidgetTitle:
2129 if (
const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<
const QStyleOptionDockWidget *>(opt)) {
2130 QRect r = dwOpt->rect.adjusted(0, 0, -1, -1);
2131 if (dwOpt->movable) {
2132 p->setPen(dwOpt->palette.color(QPalette::Dark));
2136 if (!dwOpt->title.isEmpty()) {
2137 const bool verticalTitleBar = dwOpt->verticalTitleBar;
2139 QPainterStateGuard psg(p, QPainterStateGuard::InitialState::NoSave);
2140 if (verticalTitleBar) {
2144 p->translate(r.left(), r.top() + r.width());
2146 p->translate(-r.left(), -r.top());
2149 const int indent = p->fontMetrics().descent();
2150 proxy()->drawItemText(p, r.adjusted(indent + 1, 1, -indent - 1, -1),
2151 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextHideMnemonic, dwOpt->palette,
2152 dwOpt->state & State_Enabled, dwOpt->title,
2153 QPalette::WindowText);
2159 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
2160 QPainterStateGuard psg(p);
2161 p->setClipRect(opt->rect);
2162 proxy()->drawControl(CE_HeaderSection, header, p, widget);
2164 QStyleOptionHeaderV2 subopt;
2165 QStyleOptionHeader &v1Copy = subopt;
2166 if (
auto v2 = qstyleoption_cast<
const QStyleOptionHeaderV2 *>(opt))
2170 subopt.rect = subElementRect(SE_HeaderLabel, header, widget);
2171 if (subopt.rect.isValid())
2172 proxy()->drawControl(CE_HeaderLabel, &subopt, p, widget);
2173 if (header->sortIndicator != QStyleOptionHeader::None) {
2174 subopt.rect = subElementRect(SE_HeaderArrow, opt, widget);
2175 proxy()->drawPrimitive(PE_IndicatorHeaderArrow, &subopt, p, widget);
2180 p->fillRect(opt->rect, opt->palette.windowText());
2182 case CE_HeaderSection:
2183 qDrawShadePanel(p, opt->rect, opt->palette,
2184 opt->state & State_Sunken, 1,
2185 &opt->palette.brush(QPalette::Button));
2187 case CE_HeaderEmptyArea:
2188 p->fillRect(opt->rect, opt->palette.window());
2190#if QT_CONFIG(combobox)
2191 case CE_ComboBoxLabel:
2192 if (
const QStyleOptionComboBox *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
2193 QRect editRect = proxy()->subControlRect(CC_ComboBox, cb, SC_ComboBoxEditField, widget);
2194 QPainterStateGuard psg(p);
2195 p->setClipRect(editRect);
2196 if (!cb->currentIcon.isNull()) {
2197 QIcon::Mode mode = cb->state & State_Enabled ? QIcon::Normal
2199 QPixmap pixmap = cb->currentIcon.pixmap(cb->iconSize, QStyleHelper::getDpr(p), mode);
2200 QRect iconRect(editRect);
2201 iconRect.setWidth(cb->iconSize.width() + 4);
2202 iconRect = alignedRect(cb->direction,
2203 Qt::AlignLeft | Qt::AlignVCenter,
2204 iconRect.size(), editRect);
2206 p->fillRect(iconRect, opt->palette.brush(QPalette::Base));
2207 proxy()->drawItemPixmap(p, iconRect, Qt::AlignCenter, pixmap);
2209 if (cb->direction == Qt::RightToLeft)
2210 editRect.translate(-4 - cb->iconSize.width(), 0);
2212 editRect.translate(cb->iconSize.width() + 4, 0);
2214 if (!cb->currentText.isEmpty() && !cb->editable) {
2216 proxy()->drawItemText(p, editRect.adjusted(2, 0, -2, 0),
2217 visualAlignment(cb->direction, cb->textAlignment),
2218 cb->palette, cb->state & State_Enabled, cb->currentText);
2223#if QT_CONFIG(toolbar)
2225 if (
const QStyleOptionToolBar *toolBar = qstyleoption_cast<
const QStyleOptionToolBar *>(opt)) {
2227 QStyleOptionFrame frame;
2228 frame.QStyleOption::operator=(*toolBar);
2229 frame.lineWidth = toolBar->lineWidth;
2230 frame.midLineWidth = toolBar->midLineWidth;
2231 proxy()->drawPrimitive(PE_PanelToolBar, opt, p, widget);
2233 if (widget && qobject_cast<QToolBar *>(widget->parentWidget()))
2235 qDrawShadePanel(p, toolBar->rect, toolBar->palette,
false, toolBar->lineWidth,
2236 &toolBar->palette.brush(QPalette::Button));
2240 case CE_ColumnViewGrip: {
2242 QLinearGradient g(0, 0, opt->rect.width(), 0);
2243 g.setColorAt(0, opt->palette.color(QPalette::Active, QPalette::Mid));
2244 g.setColorAt(0.5, Qt::white);
2245 p->fillRect(QRect(0, 0, opt->rect.width(), opt->rect.height()), g);
2249 pen.setWidth(opt->rect.width()/20);
2250 pen.setColor(opt->palette.color(QPalette::Active, QPalette::Dark));
2253 int line1starting = opt->rect.width()*8 / 20;
2254 int line2starting = opt->rect.width()*13 / 20;
2255 int top = opt->rect.height()*20/75;
2256 int bottom = opt->rect.height() - 1 - top;
2257 p->drawLine(line1starting, top, line1starting, bottom);
2258 p->drawLine(line2starting, top, line2starting, bottom);
2262#if QT_CONFIG(itemviews)
2263 case CE_ItemViewItem:
2264 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
2265 QPainterStateGuard psg(p);
2267 const QRegion clipRegion = p->hasClipping() ? (p->clipRegion() & opt->rect) : opt->rect;
2268 p->setClipRegion(clipRegion);
2270 QRect checkRect = proxy()->subElementRect(SE_ItemViewItemCheckIndicator, vopt, widget);
2271 QRect iconRect = proxy()->subElementRect(SE_ItemViewItemDecoration, vopt, widget);
2272 QRect textRect = proxy()->subElementRect(SE_ItemViewItemText, vopt, widget);
2275 proxy()->drawPrimitive(PE_PanelItemViewItem, opt, p, widget);
2278 if (vopt->features & QStyleOptionViewItem::HasCheckIndicator) {
2279 QStyleOptionViewItem option(*vopt);
2280 option.rect = checkRect;
2281 option.state = option.state & ~QStyle::State_HasFocus;
2283 switch (vopt->checkState) {
2285 option.state |= QStyle::State_Off;
2287 case Qt::PartiallyChecked:
2288 option.state |= QStyle::State_NoChange;
2291 option.state |= QStyle::State_On;
2294 proxy()->drawPrimitive(QStyle::PE_IndicatorItemViewItemCheck, &option, p, widget);
2298 QIcon::Mode mode = QIcon::Normal;
2299 if (!(vopt->state & QStyle::State_Enabled))
2300 mode = QIcon::Disabled;
2301 else if (vopt->state & QStyle::State_Selected)
2302 mode = QIcon::Selected;
2303 QIcon::State state = vopt->state & QStyle::State_Open ? QIcon::On : QIcon::Off;
2304 vopt->icon.paint(p, iconRect, vopt->decorationAlignment, mode, state);
2307 if (!vopt->text.isEmpty()) {
2308 QPalette::ColorGroup cg = vopt->state & QStyle::State_Enabled
2309 ? QPalette::Normal : QPalette::Disabled;
2310 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))
2311 cg = QPalette::Inactive;
2313 if (vopt->state & QStyle::State_Selected) {
2314 p->setPen(vopt->palette.color(cg, QPalette::HighlightedText));
2316 p->setPen(vopt->palette.color(cg, QPalette::Text));
2318 if (vopt->state & QStyle::State_Editing) {
2319 p->setPen(vopt->palette.color(cg, QPalette::Text));
2320 p->drawRect(textRect.adjusted(0, 0, -1, -1));
2323 d->viewItemDrawText(p, vopt, textRect);
2327 if (vopt->state & QStyle::State_HasFocus) {
2328 QStyleOptionFocusRect o;
2329 o.QStyleOption::operator=(*vopt);
2330 o.rect = proxy()->subElementRect(SE_ItemViewItemFocusRect, vopt, widget);
2331 o.state |= QStyle::State_KeyboardFocusChange;
2332 o.state |= QStyle::State_Item;
2333 QPalette::ColorGroup cg = (vopt->state & QStyle::State_Enabled)
2334 ? QPalette::Normal : QPalette::Disabled;
2335 o.backgroundColor = vopt->palette.color(cg, (vopt->state & QStyle::State_Selected)
2336 ? QPalette::Highlight : QPalette::Window);
2337 proxy()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, p, widget);
2344 case CE_ShapedFrame:
2345 if (
const QStyleOptionFrame *f = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
2346 int frameShape = f->frameShape;
2347 int frameShadow = QFrame::Plain;
2348 if (f->state & QStyle::State_Sunken) {
2349 frameShadow = QFrame::Sunken;
2350 }
else if (f->state & QStyle::State_Raised) {
2351 frameShadow = QFrame::Raised;
2354 int lw = f->lineWidth;
2355 int mlw = f->midLineWidth;
2356 QPalette::ColorRole foregroundRole = QPalette::WindowText;
2358 foregroundRole = widget->foregroundRole();
2360 switch (frameShape) {
2362 if (frameShadow == QFrame::Plain) {
2363 qDrawPlainRect(p, f->rect, f->palette.color(foregroundRole), lw);
2365 qDrawShadeRect(p, f->rect, f->palette, frameShadow == QFrame::Sunken, lw, mlw);
2368 case QFrame::StyledPanel:
2372 widget->style()->drawPrimitive(QStyle::PE_Frame, opt, p, widget);
2374 proxy()->drawPrimitive(QStyle::PE_Frame, opt, p, widget);
2378 if (frameShadow == QFrame::Plain) {
2379 qDrawPlainRect(p, f->rect, f->palette.color(foregroundRole), lw);
2381 qDrawShadePanel(p, f->rect, f->palette, frameShadow == QFrame::Sunken, lw);
2384 case QFrame::WinPanel:
2385 if (frameShadow == QFrame::Plain) {
2386 qDrawPlainRect(p, f->rect, f->palette.color(foregroundRole), lw);
2388 qDrawWinPanel(p, f->rect, f->palette, frameShadow == QFrame::Sunken);
2392 case QFrame::VLine: {
2394 if (frameShape == QFrame::HLine) {
2395 p1 = QPoint(opt->rect.x(), opt->rect.y() + opt->rect.height() / 2);
2396 p2 = QPoint(opt->rect.x() + opt->rect.width(), p1.y());
2398 p1 = QPoint(opt->rect.x() + opt->rect.width() / 2, opt->rect.y());
2399 p2 = QPoint(p1.x(), p1.y() + opt->rect.height());
2401 if (frameShadow == QFrame::Plain) {
2402 QPen oldPen = p->pen();
2403 p->setPen(QPen(opt->palette.brush(foregroundRole), lw));
2404 p->drawLine(p1, p2);
2407 qDrawShadeLine(p, p1, p2, f->palette, frameShadow == QFrame::Sunken, lw, mlw);
2418#if !QT_CONFIG(tabbar) && !QT_CONFIG(itemviews)
2426QRect QCommonStyle::subElementRect(SubElement sr,
const QStyleOption *opt,
2427 const QWidget *widget)
const
2429 Q_D(
const QCommonStyle);
2432 case SE_PushButtonContents:
2433 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
2435 dx1 = proxy()->pixelMetric(PM_DefaultFrameWidth, btn, widget);
2436 if (btn->features & QStyleOptionButton::AutoDefaultButton)
2437 dx1 += proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
2439 r.setRect(opt->rect.x() + dx1, opt->rect.y() + dx1, opt->rect.width() - dx2,
2440 opt->rect.height() - dx2);
2441 r = visualRect(opt->direction, opt->rect, r);
2444 case SE_PushButtonFocusRect:
2445 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
2446 int dbw1 = 0, dbw2 = 0;
2447 if (btn->features & QStyleOptionButton::AutoDefaultButton){
2448 dbw1 = proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
2452 int dfw1 = proxy()->pixelMetric(PM_DefaultFrameWidth, btn, widget) + 1,
2455 r.setRect(btn->rect.x() + dfw1 + dbw1, btn->rect.y() + dfw1 + dbw1,
2456 btn->rect.width() - dfw2 - dbw2, btn->rect.height()- dfw2 - dbw2);
2457 r = visualRect(opt->direction, opt->rect, r);
2460 case SE_PushButtonBevel:
2463 r = visualRect(opt->direction, opt->rect, r);
2466 case SE_CheckBoxIndicator:
2468 int h = proxy()->pixelMetric(PM_IndicatorHeight, opt, widget);
2469 r.setRect(opt->rect.x(), opt->rect.y() + ((opt->rect.height() - h) / 2),
2470 proxy()->pixelMetric(PM_IndicatorWidth, opt, widget), h);
2471 r = visualRect(opt->direction, opt->rect, r);
2475 case SE_CheckBoxContents:
2478 QRect ir = visualRect(opt->direction, opt->rect,
2479 subElementRect(SE_CheckBoxIndicator, opt, widget));
2480 int spacing = proxy()->pixelMetric(PM_CheckBoxLabelSpacing, opt, widget);
2481 r.setRect(ir.right() + spacing, opt->rect.y(), opt->rect.width() - ir.width() - spacing,
2482 opt->rect.height());
2483 r = visualRect(opt->direction, opt->rect, r);
2487 case SE_CheckBoxFocusRect:
2488 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
2489 if (btn->icon.isNull() && btn->text.isEmpty()) {
2490 r = subElementRect(SE_CheckBoxIndicator, opt, widget);
2491 r.adjust(1, 1, -1, -1);
2495 QRect cr = visualRect(btn->direction, btn->rect,
2496 subElementRect(SE_CheckBoxContents, btn, widget));
2498 QRect iconRect, textRect;
2499 if (!btn->text.isEmpty()) {
2500 textRect = itemTextRect(opt->fontMetrics, cr, Qt::AlignAbsolute | Qt::AlignLeft
2501 | Qt::AlignVCenter | Qt::TextShowMnemonic,
2502 btn->state & State_Enabled, btn->text);
2504 if (!btn->icon.isNull()) {
2505 iconRect = itemPixmapRect(cr, Qt::AlignAbsolute | Qt::AlignLeft | Qt::AlignVCenter
2506 | Qt::TextShowMnemonic,
2507 btn->icon.pixmap(btn->iconSize, QStyleHelper::getDpr(widget), QIcon::Normal));
2508 if (!textRect.isEmpty())
2509 textRect.translate(iconRect.right() + 4, 0);
2511 r = iconRect | textRect;
2512 r.adjust(-3, -2, 3, 2);
2513 r = r.intersected(btn->rect);
2514 r = visualRect(btn->direction, btn->rect, r);
2518 case SE_RadioButtonIndicator:
2520 int h = proxy()->pixelMetric(PM_ExclusiveIndicatorHeight, opt, widget);
2521 r.setRect(opt->rect.x(), opt->rect.y() + ((opt->rect.height() - h) / 2),
2522 proxy()->pixelMetric(PM_ExclusiveIndicatorWidth, opt, widget), h);
2523 r = visualRect(opt->direction, opt->rect, r);
2527 case SE_RadioButtonContents:
2529 QRect ir = visualRect(opt->direction, opt->rect,
2530 subElementRect(SE_RadioButtonIndicator, opt, widget));
2531 int spacing = proxy()->pixelMetric(PM_RadioButtonLabelSpacing, opt, widget);
2532 r.setRect(ir.left() + ir.width() + spacing, opt->rect.y(), opt->rect.width() - ir.width() - spacing,
2533 opt->rect.height());
2534 r = visualRect(opt->direction, opt->rect, r);
2538 case SE_RadioButtonFocusRect:
2539 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
2540 if (btn->icon.isNull() && btn->text.isEmpty()) {
2541 r = subElementRect(SE_RadioButtonIndicator, opt, widget);
2542 r.adjust(1, 1, -1, -1);
2545 QRect cr = visualRect(btn->direction, btn->rect,
2546 subElementRect(SE_RadioButtonContents, opt, widget));
2548 QRect iconRect, textRect;
2549 if (!btn->text.isEmpty()){
2550 textRect = itemTextRect(opt->fontMetrics, cr, Qt::AlignAbsolute | Qt::AlignLeft | Qt::AlignVCenter
2551 | Qt::TextShowMnemonic, btn->state & State_Enabled, btn->text);
2553 if (!btn->icon.isNull()) {
2554 iconRect = itemPixmapRect(cr, Qt::AlignAbsolute | Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic,
2555 btn->icon.pixmap(btn->iconSize, QStyleHelper::getDpr(widget), QIcon::Normal));
2556 if (!textRect.isEmpty())
2557 textRect.translate(iconRect.right() + 4, 0);
2559 r = iconRect | textRect;
2560 r.adjust(-3, -2, 3, 2);
2561 r = r.intersected(btn->rect);
2562 r = visualRect(btn->direction, btn->rect, r);
2565#if QT_CONFIG(slider)
2566 case SE_SliderFocusRect:
2567 if (
const QStyleOptionSlider *slider = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
2568 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider, widget);
2569 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
2570 if (slider->orientation == Qt::Horizontal)
2571 r.setRect(0, tickOffset - 1, slider->rect.width(), thickness + 2);
2573 r.setRect(tickOffset - 1, 0, thickness + 2, slider->rect.height());
2574 r = r.intersected(slider->rect);
2575 r = visualRect(opt->direction, opt->rect, r);
2579#if QT_CONFIG(progressbar)
2580 case SE_ProgressBarGroove:
2581 case SE_ProgressBarContents:
2582 case SE_ProgressBarLabel:
2583 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
2585 const bool vertical = !(pb->state & QStyle::State_Horizontal);
2587 if (pb->textVisible)
2588 textw = qMax(pb->fontMetrics.horizontalAdvance(pb->text), pb->fontMetrics.horizontalAdvance(
"100%"_L1)) + 6;
2591 if ((pb->textAlignment & Qt::AlignCenter) == 0) {
2592 if (sr != SE_ProgressBarLabel)
2593 r.setCoords(pb->rect.left(), pb->rect.top(),
2594 pb->rect.right() - textw, pb->rect.bottom());
2596 r.setCoords(pb->rect.right() - textw, pb->rect.top(),
2597 pb->rect.right(), pb->rect.bottom());
2601 r = visualRect(pb->direction, pb->rect, r);
2605#if QT_CONFIG(combobox)
2606 case SE_ComboBoxFocusRect:
2607 if (
const QStyleOptionComboBox *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
2608 int margin = cb->frame ? 3 : 0;
2609 r.setRect(opt->rect.left() + margin, opt->rect.top() + margin,
2610 opt->rect.width() - 2*margin - 16, opt->rect.height() - 2*margin);
2611 r = visualRect(opt->direction, opt->rect, r);
2615#if QT_CONFIG(toolbox)
2616 case SE_ToolBoxTabContents:
2618 r.adjust(0, 0, -30, 0);
2621 case SE_HeaderLabel: {
2622 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget);
2623 r.setRect(opt->rect.x() + margin, opt->rect.y() + margin,
2624 opt->rect.width() - margin * 2, opt->rect.height() - margin * 2);
2626 if (
const QStyleOptionHeader *header = qstyleoption_cast<
const QStyleOptionHeader *>(opt)) {
2628 if (header->sortIndicator != QStyleOptionHeader::None) {
2629 if (opt->state & State_Horizontal)
2630 r.setWidth(r.width() - (opt->rect.height() / 2) - (margin * 2));
2632 r.setHeight(r.height() - (opt->rect.width() / 2) - (margin * 2));
2635 r = visualRect(opt->direction, opt->rect, r);
2637 case SE_HeaderArrow: {
2638 int h = opt->rect.height();
2639 int w = opt->rect.width();
2640 int x = opt->rect.x();
2641 int y = opt->rect.y();
2642 int margin = proxy()->pixelMetric(QStyle::PM_HeaderMargin, opt, widget);
2644 if (opt->state & State_Horizontal) {
2645 int horiz_size = h / 2;
2646 r.setRect(x + w - margin * 2 - horiz_size, y + 5,
2647 horiz_size, h - margin * 2 - 5);
2649 int vert_size = w / 2;
2650 r.setRect(x + 5, y + h - margin * 2 - vert_size,
2651 w - margin * 2 - 5, vert_size);
2653 r = visualRect(opt->direction, opt->rect, r);
2656 case SE_RadioButtonClickRect:
2657 r = subElementRect(SE_RadioButtonFocusRect, opt, widget);
2658 r |= subElementRect(SE_RadioButtonIndicator, opt, widget);
2660 case SE_CheckBoxClickRect:
2661 r = subElementRect(SE_CheckBoxFocusRect, opt, widget);
2662 r |= subElementRect(SE_CheckBoxIndicator, opt, widget);
2664#if QT_CONFIG(tabwidget)
2665 case SE_TabWidgetTabBar:
2666 if (
const QStyleOptionTabWidgetFrame *twf
2667 = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
2668 r.setSize(twf->tabBarSize);
2669 const uint alingMask = Qt::AlignLeft | Qt::AlignRight | Qt::AlignHCenter;
2670 switch (twf->shape) {
2671 case QTabBar::RoundedNorth:
2672 case QTabBar::TriangularNorth:
2675 r.setWidth(qMin(r.width(), twf->rect.width()
2676 - twf->leftCornerWidgetSize.width()
2677 - twf->rightCornerWidgetSize.width()));
2678 switch (proxy()->styleHint(SH_TabBar_Alignment, twf, widget) & alingMask) {
2681 r.moveTopLeft(QPoint(twf->leftCornerWidgetSize.width(), 0));
2683 case Qt::AlignHCenter:
2684 r.moveTopLeft(QPoint(twf->rect.center().x() - qRound(r.width() / 2.0f)
2685 + (twf->leftCornerWidgetSize.width() / 2)
2686 - (twf->rightCornerWidgetSize.width() / 2), 0));
2688 case Qt::AlignRight:
2689 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width()
2690 - twf->rightCornerWidgetSize.width(), 0));
2693 r = visualRect(twf->direction, twf->rect, r);
2695 case QTabBar::RoundedSouth:
2696 case QTabBar::TriangularSouth:
2697 r.setWidth(qMin(r.width(), twf->rect.width()
2698 - twf->leftCornerWidgetSize.width()
2699 - twf->rightCornerWidgetSize.width()));
2700 switch (proxy()->styleHint(SH_TabBar_Alignment, twf, widget) & alingMask) {
2703 r.moveTopLeft(QPoint(twf->leftCornerWidgetSize.width(),
2704 twf->rect.height() - twf->tabBarSize.height()));
2706 case Qt::AlignHCenter:
2707 r.moveTopLeft(QPoint(twf->rect.center().x() - qRound(r.width() / 2.0f)
2708 + (twf->leftCornerWidgetSize.width() / 2)
2709 - (twf->rightCornerWidgetSize.width() / 2),
2710 twf->rect.height() - twf->tabBarSize.height()));
2712 case Qt::AlignRight:
2713 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width()
2714 - twf->rightCornerWidgetSize.width(),
2715 twf->rect.height() - twf->tabBarSize.height()));
2718 r = visualRect(twf->direction, twf->rect, r);
2720 case QTabBar::RoundedEast:
2721 case QTabBar::TriangularEast:
2722 r.setHeight(qMin(r.height(), twf->rect.height()
2723 - twf->leftCornerWidgetSize.height()
2724 - twf->rightCornerWidgetSize.height()));
2725 switch (proxy()->styleHint(SH_TabBar_Alignment, twf, widget) & alingMask) {
2728 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width(),
2729 twf->leftCornerWidgetSize.height()));
2731 case Qt::AlignHCenter:
2732 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width(),
2733 twf->rect.center().y() - r.height() / 2));
2735 case Qt::AlignRight:
2736 r.moveTopLeft(QPoint(twf->rect.width() - twf->tabBarSize.width(),
2737 twf->rect.height() - twf->tabBarSize.height()
2738 - twf->rightCornerWidgetSize.height()));
2742 case QTabBar::RoundedWest:
2743 case QTabBar::TriangularWest:
2744 r.setHeight(qMin(r.height(), twf->rect.height()
2745 - twf->leftCornerWidgetSize.height()
2746 - twf->rightCornerWidgetSize.height()));
2747 switch (proxy()->styleHint(SH_TabBar_Alignment, twf, widget) & alingMask) {
2750 r.moveTopLeft(QPoint(0, twf->leftCornerWidgetSize.height()));
2752 case Qt::AlignHCenter:
2753 r.moveTopLeft(QPoint(0, twf->rect.center().y() - r.height() / 2));
2755 case Qt::AlignRight:
2756 r.moveTopLeft(QPoint(0, twf->rect.height() - twf->tabBarSize.height()
2757 - twf->rightCornerWidgetSize.height()));
2764 case SE_TabWidgetTabPane:
2765 case SE_TabWidgetTabContents:
2766 if (
const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
2767 QStyleOptionTab tabopt;
2768 tabopt.shape = twf->shape;
2769 int overlap = proxy()->pixelMetric(PM_TabBarBaseOverlap, &tabopt, widget);
2770 if (twf->lineWidth == 0)
2772 switch (twf->shape) {
2773 case QTabBar::RoundedNorth:
2774 case QTabBar::TriangularNorth:
2775 r = QRect(QPoint(0,qMax(twf->tabBarSize.height() - overlap, 0)),
2776 QSize(twf->rect.width(), qMin(twf->rect.height() - twf->tabBarSize.height() + overlap, twf->rect.height())));
2778 case QTabBar::RoundedSouth:
2779 case QTabBar::TriangularSouth:
2780 r = QRect(QPoint(0,0), QSize(twf->rect.width(), qMin(twf->rect.height() - twf->tabBarSize.height() + overlap, twf->rect.height())));
2782 case QTabBar::RoundedEast:
2783 case QTabBar::TriangularEast:
2784 r = QRect(QPoint(0, 0), QSize(qMin(twf->rect.width() - twf->tabBarSize.width() + overlap, twf->rect.width()), twf->rect.height()));
2786 case QTabBar::RoundedWest:
2787 case QTabBar::TriangularWest:
2788 r = QRect(QPoint(qMax(twf->tabBarSize.width() - overlap, 0), 0),
2789 QSize(qMin(twf->rect.width() - twf->tabBarSize.width() + overlap, twf->rect.width()), twf->rect.height()));
2792 if (sr == SE_TabWidgetTabContents && twf->lineWidth > 0)
2793 r.adjust(2, 2, -2, -2);
2796 case SE_TabWidgetLeftCorner:
2797 if (
const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
2798 QRect paneRect = subElementRect(SE_TabWidgetTabPane, twf, widget);
2799 switch (twf->shape) {
2800 case QTabBar::RoundedNorth:
2801 case QTabBar::TriangularNorth:
2802 r = QRect(QPoint(paneRect.x(), paneRect.y() - twf->leftCornerWidgetSize.height()),
2803 twf->leftCornerWidgetSize);
2805 case QTabBar::RoundedSouth:
2806 case QTabBar::TriangularSouth:
2807 r = QRect(QPoint(paneRect.x(), paneRect.height()), twf->leftCornerWidgetSize);
2812 r = visualRect(twf->direction, twf->rect, r);
2815 case SE_TabWidgetRightCorner:
2816 if (
const QStyleOptionTabWidgetFrame *twf = qstyleoption_cast<
const QStyleOptionTabWidgetFrame *>(opt)) {
2817 QRect paneRect = subElementRect(SE_TabWidgetTabPane, twf, widget);
2818 switch (twf->shape) {
2819 case QTabBar::RoundedNorth:
2820 case QTabBar::TriangularNorth:
2821 r = QRect(QPoint(paneRect.width() - twf->rightCornerWidgetSize.width(),
2822 paneRect.y() - twf->rightCornerWidgetSize.height()),
2823 twf->rightCornerWidgetSize);
2825 case QTabBar::RoundedSouth:
2826 case QTabBar::TriangularSouth:
2827 r = QRect(QPoint(paneRect.width() - twf->rightCornerWidgetSize.width(),
2828 paneRect.height()), twf->rightCornerWidgetSize);
2833 r = visualRect(twf->direction, twf->rect, r);
2836 case SE_TabBarTabText:
2837 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
2838 QRect dummyIconRect;
2839 d->tabLayout(tab, widget, &r, &dummyIconRect);
2842 case SE_TabBarTabLeftButton:
2843 case SE_TabBarTabRightButton:
2844 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
2845 bool selected = tab->state & State_Selected;
2846 int verticalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftVertical, tab, widget);
2847 int horizontalShift = proxy()->pixelMetric(QStyle::PM_TabBarTabShiftHorizontal, tab, widget);
2848 int hpadding = proxy()->pixelMetric(QStyle::PM_TabBarTabHSpace, opt, widget) / 2;
2849 hpadding = qMax(hpadding, 4);
2851 bool verticalTabs = tab->shape == QTabBar::RoundedEast
2852 || tab->shape == QTabBar::RoundedWest
2853 || tab->shape == QTabBar::TriangularEast
2854 || tab->shape == QTabBar::TriangularWest;
2856 QRect tr = tab->rect;
2857 if (tab->shape == QTabBar::RoundedSouth || tab->shape == QTabBar::TriangularSouth)
2858 verticalShift = -verticalShift;
2860 qSwap(horizontalShift, verticalShift);
2861 horizontalShift *= -1;
2862 verticalShift *= -1;
2864 if (tab->shape == QTabBar::RoundedWest || tab->shape == QTabBar::TriangularWest)
2865 horizontalShift = -horizontalShift;
2867 tr.adjust(0, 0, horizontalShift, verticalShift);
2870 tr.setBottom(tr.bottom() - verticalShift);
2871 tr.setRight(tr.right() - horizontalShift);
2874 QSize size = (sr == SE_TabBarTabLeftButton) ? tab->leftButtonSize : tab->rightButtonSize;
2875 int w = size.width();
2876 int h = size.height();
2877 int midHeight =
static_cast<
int>(qCeil(
float(tr.height() - h) / 2));
2878 int midWidth = ((tr.width() - w) / 2);
2880 bool atTheTop =
true;
2881 switch (tab->shape) {
2882 case QTabBar::RoundedWest:
2883 case QTabBar::TriangularWest:
2884 atTheTop = (sr == SE_TabBarTabLeftButton);
2886 case QTabBar::RoundedEast:
2887 case QTabBar::TriangularEast:
2888 atTheTop = (sr == SE_TabBarTabRightButton);
2891 if (sr == SE_TabBarTabLeftButton)
2892 r = QRect(tab->rect.x() + hpadding, midHeight, w, h);
2894 r = QRect(tab->rect.right() - w - hpadding, midHeight, w, h);
2895 r = visualRect(tab->direction, tab->rect, r);
2899 r = QRect(midWidth, tr.y() + tab->rect.height() - hpadding - h, w, h);
2901 r = QRect(midWidth, tr.y() + hpadding, w, h);
2907#if QT_CONFIG(tabbar)
2908 case SE_TabBarTearIndicator:
2909 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
2910 switch (tab->shape) {
2911 case QTabBar::RoundedNorth:
2912 case QTabBar::TriangularNorth:
2913 case QTabBar::RoundedSouth:
2914 case QTabBar::TriangularSouth:
2915 r.setRect(tab->rect.left(), tab->rect.top(), 8, opt->rect.height());
2917 case QTabBar::RoundedWest:
2918 case QTabBar::TriangularWest:
2919 case QTabBar::RoundedEast:
2920 case QTabBar::TriangularEast:
2921 r.setRect(tab->rect.left(), tab->rect.top(), opt->rect.width(), 8);
2926 r = visualRect(opt->direction, opt->rect, r);
2929 case SE_TabBarScrollLeftButton: {
2930 const bool vertical = opt->rect.width() < opt->rect.height();
2931 const Qt::LayoutDirection ld = widget->layoutDirection();
2932 const int buttonWidth = proxy()->pixelMetric(QStyle::PM_TabBarScrollButtonWidth,
nullptr, widget);
2933 const int buttonOverlap = proxy()->pixelMetric(QStyle::PM_TabBar_ScrollButtonOverlap,
nullptr, widget);
2935 r = vertical ? QRect(0, opt->rect.height() - (buttonWidth * 2) + buttonOverlap, opt->rect.width(), buttonWidth)
2936 : QStyle::visualRect(ld, opt->rect, QRect(opt->rect.width() - (buttonWidth * 2) + buttonOverlap, 0, buttonWidth, opt->rect.height()));
2938 case SE_TabBarScrollRightButton: {
2939 const bool vertical = opt->rect.width() < opt->rect.height();
2940 const Qt::LayoutDirection ld = widget->layoutDirection();
2941 const int buttonWidth = proxy()->pixelMetric(QStyle::PM_TabBarScrollButtonWidth,
nullptr, widget);
2943 r = vertical ? QRect(0, opt->rect.height() - buttonWidth, opt->rect.width(), buttonWidth)
2944 : QStyle::visualRect(ld, opt->rect, QRect(opt->rect.width() - buttonWidth, 0, buttonWidth, opt->rect.height()));
2947 case SE_TreeViewDisclosureItem:
2950 case SE_LineEditContents:
2951 if (
const QStyleOptionFrame *f = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
2952 r = f->rect.adjusted(f->lineWidth, f->lineWidth, -f->lineWidth, -f->lineWidth);
2953 r = visualRect(opt->direction, opt->rect, r);
2956 case SE_FrameContents:
2957 if (
const QStyleOptionFrame *f = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
2958 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, f, widget);
2959 r = opt->rect.adjusted(fw, fw, -fw, -fw);
2960 r = visualRect(opt->direction, opt->rect, r);
2963 case SE_ShapedFrameContents:
2964 if (
const QStyleOptionFrame *f = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
2965 int frameShape = f->frameShape;
2966 int frameShadow = QFrame::Plain;
2967 if (f->state & QStyle::State_Sunken) {
2968 frameShadow = QFrame::Sunken;
2969 }
else if (f->state & QStyle::State_Raised) {
2970 frameShadow = QFrame::Raised;
2975 switch (frameShape) {
2976 case QFrame::NoFrame:
2983 switch (frameShadow) {
2985 frameWidth = f->lineWidth;
2987 case QFrame::Raised:
2988 case QFrame::Sunken:
2989 frameWidth = (
short)(f->lineWidth*2 + f->midLineWidth);
2994 case QFrame::StyledPanel:
2998 return widget->style()->subElementRect(QStyle::SE_FrameContents, opt, widget);
3000 return subElementRect(QStyle::SE_FrameContents, opt, widget);
3002 case QFrame::WinPanel:
3007 switch (frameShadow) {
3009 case QFrame::Raised:
3010 case QFrame::Sunken:
3011 frameWidth = f->lineWidth;
3016 r = f->rect.adjusted(frameWidth, frameWidth, -frameWidth, -frameWidth);
3019#if QT_CONFIG(dockwidget)
3020 case SE_DockWidgetCloseButton:
3021 case SE_DockWidgetFloatButton:
3022 case SE_DockWidgetTitleBarText:
3023 case SE_DockWidgetIcon: {
3024 int iconSize = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
3025 int buttonMargin = proxy()->pixelMetric(PM_DockWidgetTitleBarButtonMargin, opt, widget);
3026 int margin = proxy()->pixelMetric(QStyle::PM_DockWidgetTitleMargin, opt, widget);
3027 QRect rect = opt->rect;
3029 const QStyleOptionDockWidget *dwOpt
3030 = qstyleoption_cast<
const QStyleOptionDockWidget*>(opt);
3031 bool canClose = dwOpt ==
nullptr ?
true : dwOpt->closable;
3032 bool canFloat = dwOpt ==
nullptr ?
false : dwOpt->floatable;
3034 const bool verticalTitleBar = dwOpt && dwOpt->verticalTitleBar;
3039 if (verticalTitleBar)
3040 rect = rect.transposed();
3044 int right = rect.right();
3045 int left = rect.left();
3049 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarCloseButton,
3050 opt, widget).actualSize(QSize(iconSize, iconSize));
3051 sz += QSize(buttonMargin, buttonMargin);
3052 if (verticalTitleBar)
3053 sz = sz.transposed();
3054 closeRect = QRect(right - sz.width(),
3055 rect.center().y() - sz.height()/2,
3056 sz.width(), sz.height());
3057 right = closeRect.left() - 1;
3059 if (sr == SE_DockWidgetCloseButton) {
3066 QSize sz = proxy()->standardIcon(QStyle::SP_TitleBarNormalButton,
3067 opt, widget).actualSize(QSize(iconSize, iconSize));
3068 sz += QSize(buttonMargin, buttonMargin);
3069 if (verticalTitleBar)
3070 sz = sz.transposed();
3071 floatRect = QRect(right - sz.width(),
3072 rect.center().y() - sz.height()/2,
3073 sz.width(), sz.height());
3074 right = floatRect.left() - 1;
3076 if (sr == SE_DockWidgetFloatButton) {
3082 if (
const QDockWidget *dw = qobject_cast<
const QDockWidget*>(widget)) {
3084 if (dw->isFloating())
3085 icon = dw->windowIcon();
3087 && icon.cacheKey() != QApplication::windowIcon().cacheKey()) {
3088 QSize sz = icon.actualSize(QSize(r.height(), r.height()));
3089 if (verticalTitleBar)
3090 sz = sz.transposed();
3091 iconRect = QRect(left, rect.center().y() - sz.height()/2,
3092 sz.width(), sz.height());
3093 left = iconRect.right() + margin;
3096 if (sr == SE_DockWidgetIcon) {
3101 QRect textRect = QRect(left, rect.top(),
3102 right - left, rect.height());
3103 if (sr == SE_DockWidgetTitleBarText) {
3110 if (verticalTitleBar) {
3111 r = QRect(rect.left() + r.top() - rect.top(),
3112 rect.top() + rect.right() - r.right(),
3113 r.height(), r.width());
3115 r = visualRect(opt->direction, rect, r);
3120#if QT_CONFIG(itemviews)
3121 case SE_ItemViewItemCheckIndicator:
3122 if (!qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
3123 r = subElementRect(SE_CheckBoxIndicator, opt, widget);
3127 case SE_ItemViewItemDecoration:
3128 case SE_ItemViewItemText:
3129 case SE_ItemViewItemFocusRect:
3130 if (
const QStyleOptionViewItem *vopt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt)) {
3131 if (!d->isViewItemCached(*vopt)) {
3132 d->viewItemLayout(vopt, &d->checkRect, &d->decorationRect, &d->displayRect,
false);
3133 if (d->cachedOption) {
3134 delete d->cachedOption;
3135 d->cachedOption =
nullptr;
3137 d->cachedOption =
new QStyleOptionViewItem(*vopt);
3139 if (sr == SE_ItemViewItemCheckIndicator)
3141 else if (sr == SE_ItemViewItemDecoration)
3142 r = d->decorationRect;
3143 else if (sr == SE_ItemViewItemText || sr == SE_ItemViewItemFocusRect)
3148#if QT_CONFIG(toolbar)
3149 case SE_ToolBarHandle:
3150 if (
const QStyleOptionToolBar *tbopt = qstyleoption_cast<
const QStyleOptionToolBar *>(opt)) {
3151 if (tbopt->features & QStyleOptionToolBar::Movable) {
3154 const QToolBar *tb = qobject_cast<
const QToolBar*>(widget);
3155 const QMargins margins = tb && tb->layout() ? tb->layout()->contentsMargins() : QMargins(2, 2, 2, 2);
3156 const int handleExtent = proxy()->pixelMetric(QStyle::PM_ToolBarHandleExtent, opt, tb);
3157 if (tbopt->state & QStyle::State_Horizontal) {
3158 r = QRect(margins.left(), margins.top(),
3160 tbopt->rect.height() - (margins.top() + margins.bottom()));
3161 r = QStyle::visualRect(tbopt->direction, tbopt->rect, r);
3163 r = QRect(margins.left(), margins.top(),
3164 tbopt->rect.width() - (margins.left() + margins.right()),
3175#if !QT_CONFIG(tabwidget) && !QT_CONFIG(itemviews)
3233void QCommonStyle::drawComplexControl(ComplexControl cc,
const QStyleOptionComplex *opt,
3234 QPainter *p,
const QWidget *widget)
const
3237#if QT_CONFIG(slider)
3239 if (
const QStyleOptionSlider *slider = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
3240 if (slider->subControls == SC_SliderTickmarks) {
3241 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider, widget);
3242 int ticks = slider->tickPosition;
3243 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
3244 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
3245 int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget);
3246 int interval = slider->tickInterval;
3247 if (interval <= 0) {
3248 interval = slider->singleStep;
3249 if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
3251 - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3253 interval = slider->pageStep;
3257 int fudge = len / 2;
3260 QPainterStateGuard psg(p);
3261 p->translate(slider->rect.x(), slider->rect.y());
3262 p->setPen(slider->palette.windowText().color());
3263 int v = slider->minimum;
3264 while (v <= slider->maximum + 1) {
3265 if (v == slider->maximum + 1 && interval == 1)
3267 const int v_ = qMin(v, slider->maximum);
3268 pos = QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
3269 v_, available) + fudge;
3270 if (slider->orientation == Qt::Horizontal) {
3271 if (ticks & QSlider::TicksAbove)
3272 p->drawLine(pos, 0, pos, tickOffset - 2);
3273 if (ticks & QSlider::TicksBelow)
3274 p->drawLine(pos, tickOffset + thickness + 1, pos,
3275 slider->rect.height()-1);
3277 if (ticks & QSlider::TicksAbove)
3278 p->drawLine(0, pos, tickOffset - 2, pos);
3279 if (ticks & QSlider::TicksBelow)
3280 p->drawLine(tickOffset + thickness + 1, pos,
3281 slider->rect.width()-1, pos);
3284 int nextInterval = v + interval;
3285 if (nextInterval < v)
3293#if QT_CONFIG(scrollbar)
3295 if (
const QStyleOptionSlider *scrollbar = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
3297 QStyleOptionSlider newScrollbar = *scrollbar;
3298 State saveFlags = scrollbar->state;
3300 if (scrollbar->subControls & SC_ScrollBarSubLine) {
3301 newScrollbar.state = saveFlags;
3302 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarSubLine, widget);
3303 if (newScrollbar.rect.isValid()) {
3304 if (!(scrollbar->activeSubControls & SC_ScrollBarSubLine))
3305 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3306 proxy()->drawControl(CE_ScrollBarSubLine, &newScrollbar, p, widget);
3309 if (scrollbar->subControls & SC_ScrollBarAddLine) {
3310 newScrollbar.rect = scrollbar->rect;
3311 newScrollbar.state = saveFlags;
3312 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarAddLine, widget);
3313 if (newScrollbar.rect.isValid()) {
3314 if (!(scrollbar->activeSubControls & SC_ScrollBarAddLine))
3315 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3316 proxy()->drawControl(CE_ScrollBarAddLine, &newScrollbar, p, widget);
3319 if (scrollbar->subControls & SC_ScrollBarSubPage) {
3320 newScrollbar.rect = scrollbar->rect;
3321 newScrollbar.state = saveFlags;
3322 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarSubPage, widget);
3323 if (newScrollbar.rect.isValid()) {
3324 if (!(scrollbar->activeSubControls & SC_ScrollBarSubPage))
3325 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3326 proxy()->drawControl(CE_ScrollBarSubPage, &newScrollbar, p, widget);
3329 if (scrollbar->subControls & SC_ScrollBarAddPage) {
3330 newScrollbar.rect = scrollbar->rect;
3331 newScrollbar.state = saveFlags;
3332 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarAddPage, widget);
3333 if (newScrollbar.rect.isValid()) {
3334 if (!(scrollbar->activeSubControls & SC_ScrollBarAddPage))
3335 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3336 proxy()->drawControl(CE_ScrollBarAddPage, &newScrollbar, p, widget);
3339 if (scrollbar->subControls & SC_ScrollBarFirst) {
3340 newScrollbar.rect = scrollbar->rect;
3341 newScrollbar.state = saveFlags;
3342 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarFirst, widget);
3343 if (newScrollbar.rect.isValid()) {
3344 if (!(scrollbar->activeSubControls & SC_ScrollBarFirst))
3345 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3346 proxy()->drawControl(CE_ScrollBarFirst, &newScrollbar, p, widget);
3349 if (scrollbar->subControls & SC_ScrollBarLast) {
3350 newScrollbar.rect = scrollbar->rect;
3351 newScrollbar.state = saveFlags;
3352 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarLast, widget);
3353 if (newScrollbar.rect.isValid()) {
3354 if (!(scrollbar->activeSubControls & SC_ScrollBarLast))
3355 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3356 proxy()->drawControl(CE_ScrollBarLast, &newScrollbar, p, widget);
3359 if (scrollbar->subControls & SC_ScrollBarSlider) {
3360 newScrollbar.rect = scrollbar->rect;
3361 newScrollbar.state = saveFlags;
3362 newScrollbar.rect = proxy()->subControlRect(cc, &newScrollbar, SC_ScrollBarSlider, widget);
3363 if (newScrollbar.rect.isValid()) {
3364 if (!(scrollbar->activeSubControls & SC_ScrollBarSlider))
3365 newScrollbar.state &= ~(State_Sunken | State_MouseOver);
3366 proxy()->drawControl(CE_ScrollBarSlider, &newScrollbar, p, widget);
3368 if (scrollbar->state & State_HasFocus) {
3369 QStyleOptionFocusRect fropt;
3370 fropt.QStyleOption::operator=(newScrollbar);
3371 fropt.rect.setRect(newScrollbar.rect.x() + 2, newScrollbar.rect.y() + 2,
3372 newScrollbar.rect.width() - 5,
3373 newScrollbar.rect.height() - 5);
3374 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
3381#if QT_CONFIG(spinbox)
3383 if (
const QStyleOptionSpinBox *sb = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
3384 QStyleOptionSpinBox copy = *sb;
3385 PrimitiveElement pe;
3387 if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
3388 QRect r = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxFrame, widget);
3389 qDrawWinPanel(p, r, sb->palette,
true);
3392 if (sb->subControls & SC_SpinBoxUp) {
3393 copy.subControls = SC_SpinBoxUp;
3394 QPalette pal2 = sb->palette;
3395 if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled)) {
3396 pal2.setCurrentColorGroup(QPalette::Disabled);
3397 copy.state &= ~State_Enabled;
3400 copy.palette = pal2;
3402 if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken)) {
3403 copy.state |= State_On;
3404 copy.state |= State_Sunken;
3406 copy.state |= State_Raised;
3407 copy.state &= ~State_Sunken;
3409 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
3410 : PE_IndicatorSpinUp);
3412 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget);
3413 proxy()->drawPrimitive(PE_PanelButtonBevel, ©, p, widget);
3414 copy.rect.adjust(3, 0, -4, 0);
3415 proxy()->drawPrimitive(pe, ©, p, widget);
3418 if (sb->subControls & SC_SpinBoxDown) {
3419 copy.subControls = SC_SpinBoxDown;
3420 copy.state = sb->state;
3421 QPalette pal2 = sb->palette;
3422 if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled)) {
3423 pal2.setCurrentColorGroup(QPalette::Disabled);
3424 copy.state &= ~State_Enabled;
3426 copy.palette = pal2;
3428 if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken)) {
3429 copy.state |= State_On;
3430 copy.state |= State_Sunken;
3432 copy.state |= State_Raised;
3433 copy.state &= ~State_Sunken;
3435 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
3436 : PE_IndicatorSpinDown);
3438 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget);
3439 proxy()->drawPrimitive(PE_PanelButtonBevel, ©, p, widget);
3440 copy.rect.adjust(3, 0, -4, 0);
3441 proxy()->drawPrimitive(pe, ©, p, widget);
3446#if QT_CONFIG(toolbutton)
3448 if (
const QStyleOptionToolButton *toolbutton
3449 = qstyleoption_cast<
const QStyleOptionToolButton *>(opt)) {
3450 QRect button, menuarea;
3451 button = proxy()->subControlRect(cc, toolbutton, SC_ToolButton, widget);
3452 menuarea = proxy()->subControlRect(cc, toolbutton, SC_ToolButtonMenu, widget);
3454 State bflags = toolbutton->state & ~State_Sunken;
3456 if (bflags & State_AutoRaise) {
3457 if (!(bflags & State_MouseOver) || !(bflags & State_Enabled)) {
3458 bflags &= ~State_Raised;
3461 State mflags = bflags;
3462 if (toolbutton->state & State_Sunken) {
3463 if (toolbutton->activeSubControls & SC_ToolButton)
3464 bflags |= State_Sunken;
3465 mflags |= State_Sunken;
3468 QStyleOption tool = *toolbutton;
3469 if (toolbutton->subControls & SC_ToolButton) {
3470 if (bflags & (State_Sunken | State_On | State_Raised)) {
3472 tool.state = bflags;
3473 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3477 if (toolbutton->state & State_HasFocus) {
3478 QStyleOptionFocusRect fr;
3479 fr.QStyleOption::operator=(*toolbutton);
3480 fr.rect.adjust(3, 3, -3, -3);
3481 if (toolbutton->features & QStyleOptionToolButton::MenuButtonPopup)
3482 fr.rect.adjust(0, 0, -proxy()->pixelMetric(QStyle::PM_MenuButtonIndicator,
3483 toolbutton, widget), 0);
3484 proxy()->drawPrimitive(PE_FrameFocusRect, &fr, p, widget);
3486 QStyleOptionToolButton label = *toolbutton;
3487 label.state = bflags;
3488 int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, opt, widget);
3489 label.rect = button.adjusted(fw, fw, -fw, -fw);
3490 proxy()->drawControl(CE_ToolButtonLabel, &label, p, widget);
3492 if (toolbutton->subControls & SC_ToolButtonMenu) {
3493 tool.rect = menuarea;
3494 tool.state = mflags;
3495 if (mflags & (State_Sunken | State_On | State_Raised))
3496 proxy()->drawPrimitive(PE_IndicatorButtonDropDown, &tool, p, widget);
3497 proxy()->drawPrimitive(PE_IndicatorArrowDown, &tool, p, widget);
3498 }
else if (toolbutton->features & QStyleOptionToolButton::HasMenu) {
3499 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, toolbutton, widget);
3500 QRect ir = toolbutton->rect;
3501 QStyleOptionToolButton newBtn = *toolbutton;
3502 newBtn.rect = QRect(ir.right() + 5 - mbi, ir.y() + ir.height() - mbi + 4, mbi - 6, mbi - 6);
3503 newBtn.rect = visualRect(toolbutton->direction, button, newBtn.rect);
3504 proxy()->drawPrimitive(PE_IndicatorArrowDown, &newBtn, p, widget);
3510 if (
const QStyleOptionTitleBar *tb = qstyleoption_cast<
const QStyleOptionTitleBar *>(opt)) {
3512 if (opt->subControls & SC_TitleBarLabel) {
3513 QColor left = tb->palette.highlight().color();
3514 QColor right = tb->palette.base().color();
3516 QBrush fillBrush(left);
3517 if (left != right) {
3518 QPoint p1(tb->rect.x(), tb->rect.top() + tb->rect.height()/2);
3519 QPoint p2(tb->rect.right(), tb->rect.top() + tb->rect.height()/2);
3520 QLinearGradient lg(p1, p2);
3521 lg.setColorAt(0, left);
3522 lg.setColorAt(1, right);
3526 p->fillRect(opt->rect, fillBrush);
3528 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarLabel, widget);
3530 p->setPen(tb->palette.highlightedText().color());
3531 p->drawText(ir.x() + 2, ir.y(), ir.width() - 2, ir.height(),
3532 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextSingleLine, tb->text);
3538 QStyleOption tool = *tb;
3539 if (tb->subControls & SC_TitleBarCloseButton && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3540 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarCloseButton, widget);
3541 down = tb->activeSubControls & SC_TitleBarCloseButton && (opt->state & State_Sunken);
3542 if ((tb->titleBarFlags & Qt::WindowType_Mask) == Qt::Tool
3543#if QT_CONFIG(dockwidget)
3544 || qobject_cast<
const QDockWidget *>(widget)
3547 pm = proxy()->standardIcon(SP_DockWidgetCloseButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3549 pm = proxy()->standardIcon(SP_TitleBarCloseButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3551 tool.state = down ? State_Sunken : State_Raised;
3552 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3554 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3555 : QPainterStateGuard::InitialState::NoSave);
3557 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3558 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3559 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3562 if (tb->subControls & SC_TitleBarMaxButton
3563 && tb->titleBarFlags & Qt::WindowMaximizeButtonHint
3564 && !(tb->titleBarState & Qt::WindowMaximized)) {
3565 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarMaxButton, widget);
3567 down = tb->activeSubControls & SC_TitleBarMaxButton && (opt->state & State_Sunken);
3568 pm = proxy()->standardIcon(SP_TitleBarMaxButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3570 tool.state = down ? State_Sunken : State_Raised;
3571 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3573 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3574 : QPainterStateGuard::InitialState::NoSave);
3576 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3577 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3578 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3581 if (tb->subControls & SC_TitleBarMinButton
3582 && tb->titleBarFlags & Qt::WindowMinimizeButtonHint
3583 && !(tb->titleBarState & Qt::WindowMinimized)) {
3584 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarMinButton, widget);
3585 down = tb->activeSubControls & SC_TitleBarMinButton && (opt->state & State_Sunken);
3586 pm = proxy()->standardIcon(SP_TitleBarMinButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3588 tool.state = down ? State_Sunken : State_Raised;
3589 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3591 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3592 : QPainterStateGuard::InitialState::NoSave);
3594 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3595 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3596 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3599 bool drawNormalButton = (tb->subControls & SC_TitleBarNormalButton)
3600 && (((tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
3601 && (tb->titleBarState & Qt::WindowMinimized))
3602 || ((tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
3603 && (tb->titleBarState & Qt::WindowMaximized)));
3605 if (drawNormalButton) {
3606 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarNormalButton, widget);
3607 down = tb->activeSubControls & SC_TitleBarNormalButton && (opt->state & State_Sunken);
3608 pm = proxy()->standardIcon(SP_TitleBarNormalButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3610 tool.state = down ? State_Sunken : State_Raised;
3611 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3613 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3614 : QPainterStateGuard::InitialState::NoSave);
3616 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3617 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3618 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3621 if (tb->subControls & SC_TitleBarShadeButton
3622 && tb->titleBarFlags & Qt::WindowShadeButtonHint
3623 && !(tb->titleBarState & Qt::WindowMinimized)) {
3624 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarShadeButton, widget);
3625 down = (tb->activeSubControls & SC_TitleBarShadeButton && (opt->state & State_Sunken));
3626 pm = proxy()->standardIcon(SP_TitleBarShadeButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3628 tool.state = down ? State_Sunken : State_Raised;
3629 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3631 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3632 : QPainterStateGuard::InitialState::NoSave);
3634 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3635 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3636 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3639 if (tb->subControls & SC_TitleBarUnshadeButton
3640 && tb->titleBarFlags & Qt::WindowShadeButtonHint
3641 && tb->titleBarState & Qt::WindowMinimized) {
3642 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarUnshadeButton, widget);
3644 down = tb->activeSubControls & SC_TitleBarUnshadeButton && (opt->state & State_Sunken);
3645 pm = proxy()->standardIcon(SP_TitleBarUnshadeButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3647 tool.state = down ? State_Sunken : State_Raised;
3648 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3650 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3651 : QPainterStateGuard::InitialState::NoSave);
3653 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3654 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3655 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3657 if (tb->subControls & SC_TitleBarContextHelpButton
3658 && tb->titleBarFlags & Qt::WindowContextHelpButtonHint) {
3659 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarContextHelpButton, widget);
3661 down = tb->activeSubControls & SC_TitleBarContextHelpButton && (opt->state & State_Sunken);
3662 pm = proxy()->standardIcon(SP_TitleBarContextHelpButton, &tool, widget).pixmap(QSize(10, 10), QStyleHelper::getDpr(p));
3664 tool.state = down ? State_Sunken : State_Raised;
3665 proxy()->drawPrimitive(PE_PanelButtonTool, &tool, p, widget);
3667 QPainterStateGuard psg(p, down ? QPainterStateGuard::InitialState::Save
3668 : QPainterStateGuard::InitialState::NoSave);
3670 p->translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, tb, widget),
3671 proxy()->pixelMetric(PM_ButtonShiftVertical, tb, widget));
3672 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3674 if (tb->subControls & SC_TitleBarSysMenu && tb->titleBarFlags & Qt::WindowSystemMenuHint) {
3675 ir = proxy()->subControlRect(CC_TitleBar, tb, SC_TitleBarSysMenu, widget);
3676 if (!tb->icon.isNull()) {
3677 tb->icon.paint(p, ir);
3679 int iconSize = proxy()->pixelMetric(PM_SmallIconSize, tb, widget);
3680 pm = proxy()->standardIcon(SP_TitleBarMenuButton, &tool, widget).pixmap(QSize(iconSize, iconSize), QStyleHelper::getDpr(p));
3682 proxy()->drawItemPixmap(p, ir, Qt::AlignCenter, pm);
3689 if (
const QStyleOptionSlider *dial = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
3691 QPainterStateGuard psg(p);
3694 if (p->paintEngine()->hasFeature(QPaintEngine::Antialiasing))
3695 p->setRenderHint(QPainter::Antialiasing);
3697 int width = dial->rect.width();
3698 int height = dial->rect.height();
3699 qreal r = qMin(width, height) / 2;
3701 qreal dx = dial->rect.x() + d_ + (width - 2 * r) / 2 + 1;
3702 qreal dy = dial->rect.y() + d_ + (height - 2 * r) / 2 + 1;
3703 QRect br = QRect(
int(dx),
int(dy),
int(r * 2 - 2 * d_ - 2),
int(r * 2 - 2 * d_ - 2));
3705 QPalette pal = opt->palette;
3707 if (dial->subControls & QStyle::SC_DialTickmarks) {
3708 p->setPen(pal.windowText().color());
3709 p->drawLines(QStyleHelper::calcLines(dial));
3712 if (dial->state & State_Enabled) {
3713 p->setBrush(pal.brush(QPalette::ColorRole(proxy()->styleHint(SH_Dial_BackgroundRole,
3715 p->setPen(Qt::NoPen);
3717 p->setBrush(Qt::NoBrush);
3719 p->setPen(pal.dark().color());
3720 p->drawArc(br, 60 * 16, 180 * 16);
3721 p->setPen(pal.light().color());
3722 p->drawArc(br, 240 * 16, 180 * 16);
3725 const StaticPolygonF<3> arrow = calcArrow(dial, a);
3727 p->setPen(Qt::NoPen);
3728 p->setBrush(pal.button());
3729 p->drawPolygon(arrow.cbegin(), arrow.size());
3731 a = QStyleHelper::angle(QPointF(width / 2, height / 2), arrow[0]);
3732 p->setBrush(Qt::NoBrush);
3734 if (a <= 0 || a > 200) {
3735 p->setPen(pal.light().color());
3736 p->drawLine(arrow[2], arrow[0]);
3737 p->drawLine(arrow[1], arrow[2]);
3738 p->setPen(pal.dark().color());
3739 p->drawLine(arrow[0], arrow[1]);
3740 }
else if (a > 0 && a < 45) {
3741 p->setPen(pal.light().color());
3742 p->drawLine(arrow[2], arrow[0]);
3743 p->setPen(pal.dark().color());
3744 p->drawLine(arrow[1], arrow[2]);
3745 p->drawLine(arrow[0], arrow[1]);
3746 }
else if (a >= 45 && a < 135) {
3747 p->setPen(pal.dark().color());
3748 p->drawLine(arrow[2], arrow[0]);
3749 p->drawLine(arrow[1], arrow[2]);
3750 p->setPen(pal.light().color());
3751 p->drawLine(arrow[0], arrow[1]);
3752 }
else if (a >= 135 && a < 200) {
3753 p->setPen(pal.dark().color());
3754 p->drawLine(arrow[2], arrow[0]);
3755 p->setPen(pal.light().color());
3756 p->drawLine(arrow[0], arrow[1]);
3757 p->drawLine(arrow[1], arrow[2]);
3761 QStyleOptionFocusRect fropt;
3762 fropt.rect = dial->rect;
3763 fropt.state = dial->state;
3764 fropt.palette = dial->palette;
3765 if (fropt.state & QStyle::State_HasFocus) {
3766 br.adjust(0, 0, 2, 2);
3767 if (dial->subControls & SC_DialTickmarks) {
3768 int r = qMin(width, height) / 2;
3769 br.translate(-r / 6, - r / 6);
3770 br.setWidth(br.width() + r / 3);
3771 br.setHeight(br.height() + r / 3);
3773 fropt.rect = br.adjusted(-2, -2, 2, 2);
3774 proxy()->drawPrimitive(QStyle::PE_FrameFocusRect, &fropt, p, widget);
3779#if QT_CONFIG(groupbox)
3781 if (
const QStyleOptionGroupBox *groupBox = qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
3783 QRect textRect = proxy()->subControlRect(CC_GroupBox, opt, SC_GroupBoxLabel, widget);
3784 QRect checkBoxRect = proxy()->subControlRect(CC_GroupBox, opt, SC_GroupBoxCheckBox, widget);
3785 if (groupBox->subControls & QStyle::SC_GroupBoxFrame) {
3786 QStyleOptionFrame frame;
3787 frame.QStyleOption::operator=(*groupBox);
3788 frame.features = groupBox->features;
3789 frame.lineWidth = groupBox->lineWidth;
3790 frame.midLineWidth = groupBox->midLineWidth;
3791 frame.rect = proxy()->subControlRect(CC_GroupBox, opt, SC_GroupBoxFrame, widget);
3792 QPainterStateGuard psg(p);
3793 QRegion region(groupBox->rect);
3794 if (!groupBox->text.isEmpty()) {
3795 bool ltr = groupBox->direction == Qt::LeftToRight;
3797 if (groupBox->subControls & QStyle::SC_GroupBoxCheckBox) {
3798 finalRect = checkBoxRect.united(textRect);
3799 finalRect.adjust(ltr ? -4 : 0, 0, ltr ? 0 : 4, 0);
3801 finalRect = textRect;
3803 region -= finalRect;
3805 p->setClipRegion(region);
3806 proxy()->drawPrimitive(PE_FrameGroupBox, &frame, p, widget);
3810 if ((groupBox->subControls & QStyle::SC_GroupBoxLabel) && !groupBox->text.isEmpty()) {
3811 QColor textColor = groupBox->textColor;
3812 if (textColor.isValid())
3813 p->setPen(textColor);
3814 int alignment =
int(groupBox->textAlignment);
3815 if (!proxy()->styleHint(QStyle::SH_UnderlineShortcut, opt, widget))
3816 alignment |= Qt::TextHideMnemonic;
3818 proxy()->drawItemText(p, textRect, Qt::TextShowMnemonic | Qt::AlignHCenter | alignment,
3819 groupBox->palette, groupBox->state & State_Enabled, groupBox->text,
3820 textColor.isValid() ? QPalette::NoRole : QPalette::WindowText);
3822 if (groupBox->state & State_HasFocus) {
3823 QStyleOptionFocusRect fropt;
3824 fropt.QStyleOption::operator=(*groupBox);
3825 fropt.rect = textRect;
3826 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
3831 if (groupBox->subControls & SC_GroupBoxCheckBox) {
3832 QStyleOptionButton box;
3833 box.QStyleOption::operator=(*groupBox);
3834 box.rect = checkBoxRect;
3835 proxy()->drawPrimitive(PE_IndicatorCheckBox, &box, p, widget);
3840#if QT_CONFIG(mdiarea)
3841 case CC_MdiControls:
3843 QStyleOptionButton btnOpt;
3844 btnOpt.QStyleOption::operator=(*opt);
3845 btnOpt.state &= ~State_MouseOver;
3848 const int buttonIconMetric = proxy()->pixelMetric(PM_TitleBarButtonIconSize, &btnOpt, widget);
3849 const QSize buttonIconSize(buttonIconMetric, buttonIconMetric);
3850 if (opt->subControls & QStyle::SC_MdiCloseButton) {
3851 if (opt->activeSubControls & QStyle::SC_MdiCloseButton && (opt->state & State_Sunken)) {
3852 btnOpt.state |= State_Sunken;
3853 btnOpt.state &= ~State_Raised;
3854 bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget);
3855 bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget);
3857 btnOpt.state |= State_Raised;
3858 btnOpt.state &= ~State_Sunken;
3862 btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiCloseButton, widget);
3863 proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p, widget);
3864 QPixmap pm = proxy()->standardIcon(SP_TitleBarCloseButton).pixmap(buttonIconSize, QStyleHelper::getDpr(p));
3865 proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm);
3867 if (opt->subControls & QStyle::SC_MdiNormalButton) {
3868 if (opt->activeSubControls & QStyle::SC_MdiNormalButton && (opt->state & State_Sunken)) {
3869 btnOpt.state |= State_Sunken;
3870 btnOpt.state &= ~State_Raised;
3871 bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget);
3872 bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget);
3874 btnOpt.state |= State_Raised;
3875 btnOpt.state &= ~State_Sunken;
3879 btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiNormalButton, widget);
3880 proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p, widget);
3881 QPixmap pm = proxy()->standardIcon(SP_TitleBarNormalButton).pixmap(buttonIconSize, QStyleHelper::getDpr(p));
3882 proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm);
3884 if (opt->subControls & QStyle::SC_MdiMinButton) {
3885 if (opt->activeSubControls & QStyle::SC_MdiMinButton && (opt->state & State_Sunken)) {
3886 btnOpt.state |= State_Sunken;
3887 btnOpt.state &= ~State_Raised;
3888 bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, widget);
3889 bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, widget);
3891 btnOpt.state |= State_Raised;
3892 btnOpt.state &= ~State_Sunken;
3896 btnOpt.rect = proxy()->subControlRect(CC_MdiControls, opt, SC_MdiMinButton, widget);
3897 proxy()->drawPrimitive(PE_PanelButtonCommand, &btnOpt, p, widget);
3898 QPixmap pm = proxy()->standardIcon(SP_TitleBarMinButton).pixmap(buttonIconSize, QStyleHelper::getDpr(p));
3899 proxy()->drawItemPixmap(p, btnOpt.rect.translated(bsx, bsy), Qt::AlignCenter, pm);
3905 qCWarning(lcCommonStyle,
"QCommonStyle::drawComplexControl: Control %d not handled", cc);
4049QRect QCommonStyle::subControlRect(ComplexControl cc,
const QStyleOptionComplex *opt,
4050 SubControl sc,
const QWidget *widget)
const
4054#if QT_CONFIG(slider)
4056 if (
const QStyleOptionSlider *slider = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
4057 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider, widget);
4058 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
4061 case SC_SliderHandle: {
4063 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
4064 bool horizontal = slider->orientation == Qt::Horizontal;
4065 sliderPos = sliderPositionFromValue(slider->minimum, slider->maximum,
4066 slider->sliderPosition,
4067 (horizontal ? slider->rect.width()
4068 : slider->rect.height()) - len,
4069 slider->upsideDown);
4071 ret.setRect(slider->rect.x() + sliderPos, slider->rect.y() + tickOffset, len, thickness);
4073 ret.setRect(slider->rect.x() + tickOffset, slider->rect.y() + sliderPos, thickness, len);
4075 case SC_SliderGroove:
4076 if (slider->orientation == Qt::Horizontal)
4077 ret.setRect(slider->rect.x(), slider->rect.y() + tickOffset,
4078 slider->rect.width(), thickness);
4080 ret.setRect(slider->rect.x() + tickOffset, slider->rect.y(),
4081 thickness, slider->rect.height());
4086 ret = visualRect(slider->direction, slider->rect, ret);
4090#if QT_CONFIG(scrollbar)
4092 if (
const QStyleOptionSlider *scrollbar = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
4093 const QRect scrollBarRect = scrollbar->rect;
4095 if (!proxy()->styleHint(SH_ScrollBar_Transient, scrollbar, widget))
4096 sbextent = proxy()->pixelMetric(PM_ScrollBarExtent, scrollbar, widget);
4097 int maxlen = ((scrollbar->orientation == Qt::Horizontal) ?
4098 scrollBarRect.width() : scrollBarRect.height()) - (sbextent * 2);
4102 if (scrollbar->maximum != scrollbar->minimum) {
4103 uint range = scrollbar->maximum - scrollbar->minimum;
4104 sliderlen = (qint64(scrollbar->pageStep) * maxlen) / (range + scrollbar->pageStep);
4106 int slidermin = proxy()->pixelMetric(PM_ScrollBarSliderMin, scrollbar, widget);
4107 if (sliderlen < slidermin || range > INT_MAX / 2)
4108 sliderlen = slidermin;
4109 if (sliderlen > maxlen)
4115 int sliderstart = sbextent + sliderPositionFromValue(scrollbar->minimum,
4117 scrollbar->sliderPosition,
4119 scrollbar->upsideDown);
4122 case SC_ScrollBarSubLine:
4123 if (scrollbar->orientation == Qt::Horizontal) {
4124 int buttonWidth = qMin(scrollBarRect.width() / 2, sbextent);
4125 ret.setRect(0, 0, buttonWidth, scrollBarRect.height());
4127 int buttonHeight = qMin(scrollBarRect.height() / 2, sbextent);
4128 ret.setRect(0, 0, scrollBarRect.width(), buttonHeight);
4131 case SC_ScrollBarAddLine:
4132 if (scrollbar->orientation == Qt::Horizontal) {
4133 int buttonWidth = qMin(scrollBarRect.width()/2, sbextent);
4134 ret.setRect(scrollBarRect.width() - buttonWidth, 0, buttonWidth, scrollBarRect.height());
4136 int buttonHeight = qMin(scrollBarRect.height()/2, sbextent);
4137 ret.setRect(0, scrollBarRect.height() - buttonHeight, scrollBarRect.width(), buttonHeight);
4140 case SC_ScrollBarSubPage:
4141 if (scrollbar->orientation == Qt::Horizontal)
4142 ret.setRect(sbextent, 0, sliderstart - sbextent, scrollBarRect.height());
4144 ret.setRect(0, sbextent, scrollBarRect.width(), sliderstart - sbextent);
4146 case SC_ScrollBarAddPage:
4147 if (scrollbar->orientation == Qt::Horizontal)
4148 ret.setRect(sliderstart + sliderlen, 0,
4149 maxlen - sliderstart - sliderlen + sbextent, scrollBarRect.height());
4151 ret.setRect(0, sliderstart + sliderlen, scrollBarRect.width(),
4152 maxlen - sliderstart - sliderlen + sbextent);
4154 case SC_ScrollBarGroove:
4155 if (scrollbar->orientation == Qt::Horizontal)
4156 ret.setRect(sbextent, 0, scrollBarRect.width() - sbextent * 2,
4157 scrollBarRect.height());
4159 ret.setRect(0, sbextent, scrollBarRect.width(),
4160 scrollBarRect.height() - sbextent * 2);
4162 case SC_ScrollBarSlider:
4163 if (scrollbar->orientation == Qt::Horizontal)
4164 ret.setRect(sliderstart, 0, sliderlen, scrollBarRect.height());
4166 ret.setRect(0, sliderstart, scrollBarRect.width(), sliderlen);
4171 ret = visualRect(scrollbar->direction, scrollBarRect, ret);
4175#if QT_CONFIG(spinbox)
4177 if (
const QStyleOptionSpinBox *spinbox = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
4179 int fw = spinbox->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget) : 0;
4180 bs.setHeight(qMax(8, spinbox->rect.height()/2 - fw));
4182 bs.setWidth(qMax(16, qMin(bs.height() * 8 / 5, spinbox->rect.width() / 4)));
4183 int y = fw + spinbox->rect.y();
4185 x = spinbox->rect.x() + spinbox->rect.width() - fw - bs.width();
4190 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
4192 ret = QRect(x, y, bs.width(), bs.height());
4194 case SC_SpinBoxDown:
4195 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons)
4198 ret = QRect(x, y + bs.height(), bs.width(), bs.height());
4200 case SC_SpinBoxEditField:
4201 if (spinbox->buttonSymbols == QAbstractSpinBox::NoButtons) {
4202 ret = QRect(lx, fw, spinbox->rect.width() - 2*fw, spinbox->rect.height() - 2*fw);
4204 ret = QRect(lx, fw, rx, spinbox->rect.height() - 2*fw);
4207 case SC_SpinBoxFrame:
4208 ret = spinbox->rect;
4213 ret = visualRect(spinbox->direction, spinbox->rect, ret);
4217#if QT_CONFIG(toolbutton)
4219 if (
const QStyleOptionToolButton *tb = qstyleoption_cast<
const QStyleOptionToolButton *>(opt)) {
4220 int mbi = proxy()->pixelMetric(PM_MenuButtonIndicator, tb, widget);
4225 & (QStyleOptionToolButton::MenuButtonPopup | QStyleOptionToolButton::PopupDelay))
4226 == QStyleOptionToolButton::MenuButtonPopup)
4227 ret.adjust(0, 0, -mbi, 0);
4229 case SC_ToolButtonMenu:
4231 & (QStyleOptionToolButton::MenuButtonPopup | QStyleOptionToolButton::PopupDelay))
4232 == QStyleOptionToolButton::MenuButtonPopup)
4233 ret.adjust(ret.width() - mbi, 0, 0, 0);
4238 ret = visualRect(tb->direction, tb->rect, ret);
4242#if QT_CONFIG(combobox)
4244 if (
const QStyleOptionComboBox *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
4245 const qreal dpi = QStyleHelper::dpi(opt);
4246 const int x = cb->rect.x(), y = cb->rect.y(), wi = cb->rect.width(), he = cb->rect.height();
4247 const int margin = cb->frame ? qRound(QStyleHelper::dpiScaled(3, dpi)) : 0;
4248 const int bmarg = cb->frame ? qRound(QStyleHelper::dpiScaled(2, dpi)) : 0;
4249 const int xpos = x + wi - bmarg - qRound(QStyleHelper::dpiScaled(16, dpi));
4253 case SC_ComboBoxFrame:
4256 case SC_ComboBoxArrow:
4257 ret.setRect(xpos, y + bmarg, qRound(QStyleHelper::dpiScaled(16, opt)), he - 2*bmarg);
4259 case SC_ComboBoxEditField:
4260 ret.setRect(x + margin, y + margin, wi - 2 * margin - qRound(QStyleHelper::dpiScaled(16, dpi)), he - 2 * margin);
4262 case SC_ComboBoxListBoxPopup:
4268 ret = visualRect(cb->direction, cb->rect, ret);
4273 if (
const QStyleOptionTitleBar *tb = qstyleoption_cast<
const QStyleOptionTitleBar *>(opt)) {
4274 const int controlMargin = 2;
4275 const int controlHeight = tb->rect.height() - controlMargin *2;
4276 const int delta = controlHeight + controlMargin;
4279 bool isMinimized = tb->titleBarState & Qt::WindowMinimized;
4280 bool isMaximized = tb->titleBarState & Qt::WindowMaximized;
4283 case SC_TitleBarLabel:
4284 if (tb->titleBarFlags & (Qt::WindowTitleHint | Qt::WindowSystemMenuHint)) {
4286 if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
4287 ret.adjust(delta, 0, -delta, 0);
4288 if (tb->titleBarFlags & Qt::WindowMinimizeButtonHint)
4289 ret.adjust(0, 0, -delta, 0);
4290 if (tb->titleBarFlags & Qt::WindowMaximizeButtonHint)
4291 ret.adjust(0, 0, -delta, 0);
4292 if (tb->titleBarFlags & Qt::WindowShadeButtonHint)
4293 ret.adjust(0, 0, -delta, 0);
4294 if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
4295 ret.adjust(0, 0, -delta, 0);
4298 case SC_TitleBarContextHelpButton:
4299 if (tb->titleBarFlags & Qt::WindowContextHelpButtonHint)
4302 case SC_TitleBarMinButton:
4303 if (!isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
4305 else if (sc == SC_TitleBarMinButton)
4308 case SC_TitleBarNormalButton:
4309 if (isMinimized && (tb->titleBarFlags & Qt::WindowMinimizeButtonHint))
4311 else if (isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
4313 else if (sc == SC_TitleBarNormalButton)
4316 case SC_TitleBarMaxButton:
4317 if (!isMaximized && (tb->titleBarFlags & Qt::WindowMaximizeButtonHint))
4319 else if (sc == SC_TitleBarMaxButton)
4322 case SC_TitleBarShadeButton:
4323 if (!isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
4325 else if (sc == SC_TitleBarShadeButton)
4328 case SC_TitleBarUnshadeButton:
4329 if (isMinimized && (tb->titleBarFlags & Qt::WindowShadeButtonHint))
4331 else if (sc == SC_TitleBarUnshadeButton)
4334 case SC_TitleBarCloseButton:
4335 if (tb->titleBarFlags & Qt::WindowSystemMenuHint)
4337 else if (sc == SC_TitleBarCloseButton)
4339 ret.setRect(tb->rect.right() - offset, tb->rect.top() + controlMargin,
4340 controlHeight, controlHeight);
4342 case SC_TitleBarSysMenu:
4343 if (tb->titleBarFlags & Qt::WindowSystemMenuHint) {
4344 ret.setRect(tb->rect.left() + controlMargin, tb->rect.top() + controlMargin,
4345 controlHeight, controlHeight);
4351 ret = visualRect(tb->direction, tb->rect, ret);
4354#if QT_CONFIG(groupbox)
4356 if (
const QStyleOptionGroupBox *groupBox = qstyleoption_cast<
const QStyleOptionGroupBox *>(opt)) {
4358 case SC_GroupBoxFrame:
4359 case SC_GroupBoxContents: {
4362 int verticalAlignment = proxy()->styleHint(SH_GroupBox_TextLabelVerticalAlignment, groupBox, widget);
4363 bool hasCheckBox = groupBox->subControls & QStyle::SC_GroupBoxCheckBox;
4364 if (groupBox->text.size() || hasCheckBox) {
4365 int checkBoxHeight = hasCheckBox ? proxy()->pixelMetric(PM_IndicatorHeight, groupBox, widget) : 0;
4366 topHeight = qMax(groupBox->fontMetrics.height(), checkBoxHeight);
4367 if (verticalAlignment & Qt::AlignVCenter)
4368 topMargin = topHeight / 2;
4369 else if (verticalAlignment & Qt::AlignTop)
4370 topMargin = topHeight + proxy()->pixelMetric(PM_FocusFrameVMargin, groupBox, widget);
4373 QRect frameRect = groupBox->rect;
4374 frameRect.setTop(topMargin);
4376 if (sc == SC_GroupBoxFrame) {
4382 if ((groupBox->features & QStyleOptionFrame::Flat) == 0)
4383 frameWidth = proxy()->pixelMetric(PM_DefaultFrameWidth, groupBox, widget);
4384 ret = frameRect.adjusted(frameWidth, frameWidth + topHeight - topMargin,
4385 -frameWidth, -frameWidth);
4388 case SC_GroupBoxCheckBox:
4389 case SC_GroupBoxLabel: {
4390 QFontMetrics fontMetrics = groupBox->fontMetrics;
4391 int th = fontMetrics.height();
4392 int tw = fontMetrics.size(Qt::TextShowMnemonic, groupBox->text + u' ').width();
4393 int marg = (groupBox->features & QStyleOptionFrame::Flat) ? 0 : 8;
4394 ret = groupBox->rect.adjusted(marg, 0, -marg, 0);
4396 int indicatorWidth = proxy()->pixelMetric(PM_IndicatorWidth, opt, widget);
4397 int indicatorHeight = proxy()->pixelMetric(PM_IndicatorHeight, opt, widget);
4398 int indicatorSpace = proxy()->pixelMetric(PM_CheckBoxLabelSpacing, opt, widget) - 1;
4399 bool hasCheckBox = groupBox->subControls & QStyle::SC_GroupBoxCheckBox;
4400 int checkBoxWidth = hasCheckBox ? (indicatorWidth + indicatorSpace) : 0;
4401 int checkBoxHeight = hasCheckBox ? indicatorHeight : 0;
4403 int h = qMax(th, checkBoxHeight);
4407 QRect totalRect = alignedRect(groupBox->direction, groupBox->textAlignment,
4408 QSize(tw + checkBoxWidth, h), ret);
4412 bool ltr = groupBox->direction == Qt::LeftToRight;
4415 if (sc == SC_GroupBoxCheckBox) {
4416 left = ltr ? totalRect.left() : (totalRect.right() - indicatorWidth);
4417 int top = totalRect.top() + (h - checkBoxHeight) / 2;
4418 totalRect.setRect(left, top, indicatorWidth, indicatorHeight);
4421 left = ltr ? (totalRect.left() + checkBoxWidth - 2) : totalRect.left();
4422 int top = totalRect.top() + (h - th) / 2;
4423 totalRect.setRect(left, top, totalRect.width() - checkBoxWidth, th);
4436#if QT_CONFIG(mdiarea)
4437 case CC_MdiControls:
4439 int numSubControls = 0;
4440 if (opt->subControls & SC_MdiCloseButton)
4442 if (opt->subControls & SC_MdiMinButton)
4444 if (opt->subControls & SC_MdiNormalButton)
4446 if (numSubControls == 0)
4449 int buttonWidth = opt->rect.width() / numSubControls - 1;
4452 case SC_MdiCloseButton:
4454 if (numSubControls == 1)
4456 offset += buttonWidth + 2;
4458 case SC_MdiNormalButton:
4462 if (numSubControls == 1 || (numSubControls == 2 && !(opt->subControls & SC_MdiMinButton)))
4464 if (opt->subControls & SC_MdiNormalButton)
4465 offset += buttonWidth;
4474 if (numSubControls == 1)
4476 ret = QRect(offset, 0, buttonWidth, opt->rect.height());
4481 qCWarning(lcCommonStyle,
"QCommonStyle::subControlRect: Case %d not handled", cc);
4483#if !QT_CONFIG(slider) && !QT_CONFIG(spinbox) && !QT_CONFIG(toolbutton) && !QT_CONFIG(groupbox)
5864QIcon QCommonStylePrivate::iconFromResourceTheme(QCommonStyle::StandardPixmap standardIcon,
5865 const QStyleOption *option,
5866 const QWidget *widget)
const
5868 Q_Q(
const QCommonStyle);
5870#ifndef QT_NO_IMAGEFORMAT_PNG
5871 switch (standardIcon) {
5872 case QStyle::SP_MessageBoxInformation:
5873 addIconFiles(u"information-", pngIconSizes, icon);
5875 case QStyle::SP_MessageBoxWarning:
5876 addIconFiles(u"warning-", pngIconSizes, icon);
5878 case QStyle::SP_MessageBoxCritical:
5879 addIconFiles(u"critical-", pngIconSizes, icon);
5881 case QStyle::SP_MessageBoxQuestion:
5882 addIconFiles(u"question-", pngIconSizes, icon);
5884 case QStyle::SP_FileDialogStart:
5885 addIconFiles(u"filedialog_start-", pngIconSizes, icon);
5887 case QStyle::SP_FileDialogEnd:
5888 addIconFiles(u"filedialog_end-", pngIconSizes, icon);
5890 case QStyle::SP_TitleBarMinButton:
5891 addIconFiles(u"titlebar-min-", titleBarSizes, icon);
5893 case QStyle::SP_TitleBarMaxButton:
5894 addIconFiles(u"titlebar-max-", titleBarSizes, icon);
5896 case QStyle::SP_TitleBarShadeButton:
5897 addIconFiles(u"titlebar-shade-", titleBarSizes, icon);
5899 case QStyle::SP_TitleBarUnshadeButton:
5900 addIconFiles(u"titlebar-unshade-", titleBarSizes, icon);
5902 case QStyle::SP_TitleBarContextHelpButton:
5903 addIconFiles(u"titlebar-contexthelp-", titleBarSizes, icon);
5905 case QStyle::SP_FileDialogNewFolder:
5906 addIconFiles(u"newdirectory-", pngIconSizes, icon);
5908 case QStyle::SP_FileDialogBack:
5909 return q->proxy()->standardIcon(QStyle::SP_ArrowBack, option, widget);
5910 case QStyle::SP_FileDialogToParent:
5911 return q->proxy()->standardIcon(QStyle::SP_ArrowUp, option, widget);
5912 case QStyle::SP_FileDialogDetailedView:
5913 addIconFiles(u"viewdetailed-", pngIconSizes, icon);
5915 case QStyle::SP_FileDialogInfoView:
5916 addIconFiles(u"fileinfo-", pngIconSizes, icon);
5918 case QStyle::SP_FileDialogContentsView:
5919 addIconFiles(u"filecontents-", pngIconSizes, icon);
5921 case QStyle::SP_FileDialogListView:
5922 addIconFiles(u"viewlist-", pngIconSizes, icon);
5924 case QStyle::SP_DialogOkButton:
5925 addIconFiles(u"standardbutton-ok-", pngIconSizes, icon);
5927 case QStyle::SP_DialogCancelButton:
5928 addIconFiles(u"standardbutton-cancel-", pngIconSizes, icon);
5930 case QStyle::SP_DialogHelpButton:
5931 addIconFiles(u"standardbutton-help-", pngIconSizes, icon);
5933 case QStyle::SP_DialogOpenButton:
5934 addIconFiles(u"standardbutton-open-", pngIconSizes, icon);
5936 case QStyle::SP_DialogSaveButton:
5937 addIconFiles(u"standardbutton-save-", pngIconSizes, icon);
5939 case QStyle::SP_DialogCloseButton:
5940 addIconFiles(u"standardbutton-close-", pngIconSizes, icon);
5942 case QStyle::SP_DialogApplyButton:
5943 addIconFiles(u"standardbutton-apply-", pngIconSizes, icon);
5945 case QStyle::SP_DialogResetButton:
5946 addIconFiles(u"standardbutton-clear-", pngIconSizes, icon);
5948 case QStyle::SP_DialogDiscardButton:
5949 addIconFiles(u"standardbutton-delete-", pngIconSizes, icon);
5951 case QStyle::SP_DialogYesButton:
5952 addIconFiles(u"standardbutton-yes-", pngIconSizes, icon);
5954 case QStyle::SP_DialogNoButton:
5955 addIconFiles(u"standardbutton-no-", pngIconSizes, icon);
5957 case QStyle::SP_CommandLink:
5958 case QStyle::SP_ArrowForward:
5959 return q->proxy()->standardIcon(rtl(option) ? QStyle::SP_ArrowLeft
5960 : QStyle::SP_ArrowRight,
5962 case QStyle::SP_ArrowBack:
5963 return q->proxy()->standardIcon(rtl(option) ? QStyle::SP_ArrowRight
5964 : QStyle::SP_ArrowLeft,
5966 case QStyle::SP_ArrowLeft:
5967 addIconFiles(u"arrow-left-", pngIconSizes, icon);
5969 case QStyle::SP_ArrowRight:
5970 addIconFiles(u"arrow-right-", pngIconSizes, icon);
5972 case QStyle::SP_ArrowUp:
5973 addIconFiles(u"arrow-up-", pngIconSizes, icon);
5975 case QStyle::SP_ArrowDown:
5976 addIconFiles(u"arrow-down-", pngIconSizes, icon);
5978 case QStyle::SP_DirHomeIcon:
5979 case QStyle::SP_DirIcon:
5980 addIconFiles(u"dirclosed-", pngIconSizes, icon, QIcon::Normal, QIcon::Off);
5981 addIconFiles(u"diropen-", pngIconSizes, icon, QIcon::Normal, QIcon::On);
5983 case QStyle::SP_DirOpenIcon:
5984 addIconFiles(u"diropen-", pngIconSizes, icon);
5986 case QStyle::SP_DirClosedIcon:
5987 addIconFiles(u"dirclosed-", pngIconSizes, icon);
5989 case QStyle::SP_DirLinkIcon:
5990 addIconFiles(u"dirlink-", pngIconSizes, icon);
5992 case QStyle::SP_DriveCDIcon:
5993 addIconFiles(u"cdr-", pngIconSizes, icon);
5995 case QStyle::SP_DriveFDIcon:
5996 addIconFiles(u"floppy-", pngIconSizes, icon);
5998 case QStyle::SP_DriveHDIcon:
5999 addIconFiles(u"harddrive-", pngIconSizes, icon);
6001 case QStyle::SP_DriveDVDIcon:
6002 addIconFiles(u"dvd-", pngIconSizes, icon);
6004 case QStyle::SP_DriveNetIcon:
6005 addIconFiles(u"networkdrive-", pngIconSizes, icon);
6007 case QStyle::SP_FileIcon:
6008 addIconFiles(u"file-", pngIconSizes, icon);
6010 case QStyle::SP_FileLinkIcon:
6011 addIconFiles(u"filelink-", pngIconSizes, icon);
6013 case QStyle::SP_DesktopIcon:
6014 addIconFiles(u"desktop-", {16, 32}, icon);
6016 case QStyle::SP_TrashIcon:
6017 addIconFiles(u"trash-", pngIconSizes, icon);
6019 case QStyle::SP_ComputerIcon:
6020 addIconFiles(u"computer-", {16, 32}, icon);
6022 case QStyle::SP_BrowserReload:
6023 addIconFiles(u"refresh-", {24, 32}, icon);
6025 case QStyle::SP_BrowserStop:
6026 addIconFiles(u"stop-", {24, 32}, icon);
6028 case QStyle::SP_MediaPlay:
6029 addIconFiles(u"media-play-", pngIconSizes, icon);
6031 case QStyle::SP_MediaPause:
6032 addIconFiles(u"media-pause-", pngIconSizes, icon);
6034 case QStyle::SP_MediaStop:
6035 addIconFiles(u"media-stop-", pngIconSizes, icon);
6037 case QStyle::SP_MediaSeekForward:
6038 addIconFiles(u"media-seek-forward-", pngIconSizes, icon);
6040 case QStyle::SP_MediaSeekBackward:
6041 addIconFiles(u"media-seek-backward-", pngIconSizes, icon);
6043 case QStyle::SP_MediaSkipForward:
6044 addIconFiles(u"media-skip-forward-", pngIconSizes, icon);
6046 case QStyle::SP_MediaSkipBackward:
6047 addIconFiles(u"media-skip-backward-", pngIconSizes, icon);
6049 case QStyle::SP_MediaVolume:
6050 addIconFiles(u"media-volume-", pngIconSizes, icon);
6052 case QStyle::SP_MediaVolumeMuted:
6053 addIconFiles(u"media-volume-muted-", pngIconSizes, icon);
6055 case QStyle::SP_TitleBarCloseButton:
6056 case QStyle::SP_DockWidgetCloseButton:
6057 addIconFiles(u"closedock-", dockTitleIconSizes, icon);
6059 case QStyle::SP_TitleBarMenuButton:
6060# ifndef QT_NO_IMAGEFORMAT_XPM
6061 icon.addPixmap(titleBarMenuCachedPixmapFromXPM());
6063 icon.addFile(
":/qt-project.org/qmessagebox/images/qtlogo-64.png"_L1);
6065 case QStyle::SP_TitleBarNormalButton:
6066 addIconFiles(u"normalizedockup-", dockTitleIconSizes, icon);
6068 case QStyle::SP_ToolBarHorizontalExtensionButton:
6069 addIconFiles(rtl(option) ? u"toolbar-ext-h-rtl-"_sv : u"toolbar-ext-h-"_sv, toolBarExtHSizes, icon);
6071 case QStyle::SP_ToolBarVerticalExtensionButton:
6072 addIconFiles(u"toolbar-ext-v-", toolBarExtVSizes, icon);
6074 case QStyle::SP_TabCloseButton:
6075 addIconFiles(u"standardbutton-closetab-", pngIconSizes, icon, QIcon::Normal, QIcon::Off);
6076 addIconFiles(u"standardbutton-closetab-down-", pngIconSizes, icon, QIcon::Normal, QIcon::On);
6077 addIconFiles(u"standardbutton-closetab-hover-", pngIconSizes, icon, QIcon::Active, QIcon::Off);
6079 case QStyle::SP_LineEditClearButton:
6080 addIconFiles(u"cleartext-", pngIconSizes, icon);
6086 Q_UNUSED(standardIcon);