8#if QT_CONFIG(style_windows) || defined(QT_PLUGIN)
10#include "qapplication.h"
19#include <private/qmenubar_p.h>
21#include "qpaintengine.h"
23#include "qpainterstateguard.h"
24#if QT_CONFIG(rubberband)
25#include "qrubberband.h"
27#include "qstyleoption.h"
33#if QT_CONFIG(mainwindow)
34#include "qmainwindow.h"
37#include "qtextstream.h"
38#include "qpixmapcache.h"
42#if QT_CONFIG(listview)
45#include <private/qmath_p.h>
47#include <QtGui/qpainterpath.h>
48#include <QtGui/qscreen.h>
49#include <QtGui/qwindow.h>
50#include <qpa/qplatformtheme.h>
51#include <qpa/qplatformscreen.h>
52#include <private/qguiapplication_p.h>
53#include <private/qhighdpiscaling_p.h>
54#include <qpa/qplatformintegration.h>
55#include <private/qwidget_p.h>
57#include <private/qstylehelper_p.h>
58#if QT_CONFIG(animation)
59#include <private/qstyleanimation_p.h>
68QT_BEGIN_INCLUDE_NAMESPACE
69#include "qt_windows.h"
70QT_END_INCLUDE_NAMESPACE
71# ifndef COLOR_GRADIENTACTIVECAPTION
72# define COLOR_GRADIENTACTIVECAPTION 27
74# ifndef COLOR_GRADIENTINACTIVECAPTION
75# define COLOR_GRADIENTINACTIVECAPTION 28
78Q_GUI_EXPORT HICON qt_pixmapToWinHICON(
const QPixmap &);
81QT_BEGIN_INCLUDE_NAMESPACE
83QT_END_INCLUDE_NAMESPACE
85enum QSliderDirection { SlUp, SlDown, SlLeft, SlRight };
88
89
91QWindowsStylePrivate::QWindowsStylePrivate() =
default;
94bool QWindowsStylePrivate::hasSeenAlt(
const QWidget *widget)
const
96 widget = widget->window();
97 return seenAlt.contains(widget);
101
102
103bool QWindowsStyle::eventFilter(QObject *o, QEvent *e)
106 if (!o->isWidgetType())
107 return QObject::eventFilter(o, e);
109 QWidget *widget = qobject_cast<QWidget*>(o);
112 case QEvent::KeyPress:
113 if (
static_cast<QKeyEvent *>(e)->key() == Qt::Key_Alt) {
114 widget = widget->window();
117 const QList<QWidget *> children = widget->findChildren<QWidget *>();
118 auto ignorable = [](QWidget *w) {
119 return w->isWindow() || !w->isVisible();
122 d->seenAlt.append(widget);
126 for (QWidget *w : children) {
132 case QEvent::KeyRelease:
133 if (
static_cast<QKeyEvent*>(e)->key() == Qt::Key_Alt) {
134 widget = widget->window();
138#if QT_CONFIG(menubar)
139 const QList<QMenuBar *> menuBars = widget->findChildren<QMenuBar *>();
140 for (QWidget *w : menuBars)
147 d->seenAlt.removeAll(widget);
148 d->seenAlt.removeAll(widget->window());
153 return QCommonStyle::eventFilter(o, e);
157
158
159
160
161
162
163
164
165
166
167
168
171
172
173QWindowsStyle::QWindowsStyle() : QCommonStyle(*
new QWindowsStylePrivate)
178
179
180
181
182QWindowsStyle::QWindowsStyle(QWindowsStylePrivate &dd) : QCommonStyle(dd)
188QWindowsStyle::~QWindowsStyle()
193static inline QRgb colorref2qrgb(COLORREF col)
195 return qRgb(GetRValue(col), GetGValue(col), GetBValue(col));
200void QWindowsStyle::polish(QApplication *app)
202 QCommonStyle::polish(app);
203 QWindowsStylePrivate *d =
const_cast<QWindowsStylePrivate*>(d_func());
205 if (!proxy()->styleHint(SH_UnderlineShortcut,
nullptr) && app)
206 app->installEventFilter(
this);
208 const auto &palette = QGuiApplication::palette();
209 d->activeGradientCaptionColor = palette.highlight().color();
210 d->activeCaptionColor = d->activeGradientCaptionColor;
211 d->inactiveGradientCaptionColor = palette.dark().color();
212 d->inactiveCaptionColor = d->inactiveGradientCaptionColor;
213 d->inactiveCaptionText = palette.window().color();
216 if (app->desktopSettingsAware()){
217 DWORD activeCaption = GetSysColor(COLOR_ACTIVECAPTION);
218 DWORD gradientActiveCaption = GetSysColor(COLOR_GRADIENTACTIVECAPTION);
219 DWORD inactiveCaption = GetSysColor(COLOR_INACTIVECAPTION);
220 DWORD gradientInactiveCaption = GetSysColor(COLOR_GRADIENTINACTIVECAPTION);
221 DWORD inactiveCaptionText = GetSysColor(COLOR_INACTIVECAPTIONTEXT);
222 d->activeCaptionColor = colorref2qrgb(activeCaption);
223 d->activeGradientCaptionColor = colorref2qrgb(gradientActiveCaption);
224 d->inactiveCaptionColor = colorref2qrgb(inactiveCaption);
225 d->inactiveGradientCaptionColor = colorref2qrgb(gradientInactiveCaption);
226 d->inactiveCaptionText = colorref2qrgb(inactiveCaptionText);
232void QWindowsStyle::unpolish(QApplication *app)
234 QCommonStyle::unpolish(app);
235 app->removeEventFilter(
this);
239void QWindowsStyle::polish(QWidget *widget)
241 QCommonStyle::polish(widget);
245void QWindowsStyle::unpolish(QWidget *widget)
247 QCommonStyle::unpolish(widget);
251
252
253void QWindowsStyle::polish(QPalette &pal)
255 QCommonStyle::polish(pal);
258int QWindowsStylePrivate::pixelMetricFromSystemDp(QStyle::PixelMetric pm,
const QStyleOption *,
const QWidget *widget)
266 case QStyle::PM_DockWidgetFrameWidth:
267 return GetSystemMetricsForDpi(SM_CXFRAME, dpi);
269 case QStyle::PM_TitleBarHeight: {
270 const int resizeBorderThickness =
271 GetSystemMetricsForDpi(SM_CXSIZEFRAME, dpi) + GetSystemMetricsForDpi(SM_CXPADDEDBORDER, dpi);
272 if (widget && (widget->windowType() == Qt::Tool))
273 return GetSystemMetricsForDpi(SM_CYSMCAPTION, dpi) + resizeBorderThickness;
274 return GetSystemMetricsForDpi(SM_CYCAPTION, dpi) + resizeBorderThickness;
277 case QStyle::PM_ScrollBarExtent:
279 NONCLIENTMETRICS ncm;
280 ncm.cbSize =
sizeof(NONCLIENTMETRICS);
281 if (SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &ncm, 0, dpi))
282 return qMax(ncm.iScrollHeight, ncm.iScrollWidth);
286 case QStyle::PM_MdiSubWindowFrameWidth:
287 return GetSystemMetricsForDpi(SM_CYFRAME, dpi);
296 return QWindowsStylePrivate::InvalidMetric;
299int QWindowsStylePrivate::fixedPixelMetric(QStyle::PixelMetric pm)
302 case QStyle::PM_ToolBarItemSpacing:
304 case QStyle::PM_ButtonDefaultIndicator:
305 case QStyle::PM_ButtonShiftHorizontal:
306 case QStyle::PM_ButtonShiftVertical:
307 case QStyle::PM_MenuHMargin:
308 case QStyle::PM_MenuVMargin:
309 case QStyle::PM_ToolBarItemMargin:
311 case QStyle::PM_DockWidgetSeparatorExtent:
314 case QStyle::PM_TabBarTabShiftHorizontal:
316 case QStyle::PM_TabBarTabShiftVertical:
321 case QStyle::PM_SliderLength:
326 case QStyle::PM_MenuBarHMargin:
327 case QStyle::PM_MenuBarVMargin:
328 case QStyle::PM_MenuBarPanelWidth:
330 case QStyle::PM_SmallIconSize:
332 case QStyle::PM_LargeIconSize:
334 case QStyle::PM_DockWidgetTitleMargin:
336 case QStyle::PM_DockWidgetTitleBarButtonMargin:
337 case QStyle::PM_DockWidgetFrameWidth:
341 case QStyle::PM_ToolBarHandleExtent:
346 return QWindowsStylePrivate::InvalidMetric;
349static QScreen *screenOf(
const QWidget *w)
352 if (
auto screen = qt_widget_private(
const_cast<QWidget *>(w))->associatedScreen())
355 return QGuiApplication::primaryScreen();
360qreal QWindowsStylePrivate::nativeMetricScaleFactor(
const QWidget *widget)
362 return qreal(1) / QHighDpiScaling::factor(screenOf(widget));
366
367
368int QWindowsStyle::pixelMetric(PixelMetric pm,
const QStyleOption *opt,
const QWidget *widget)
const
370 int ret = QWindowsStylePrivate::pixelMetricFromSystemDp(pm, opt, widget);
371 if (ret != QWindowsStylePrivate::InvalidMetric)
374 ret = QWindowsStylePrivate::fixedPixelMetric(pm);
375 if (ret != QWindowsStylePrivate::InvalidMetric)
376 return int(QStyleHelper::dpiScaled(ret, opt));
381 case PM_MaximumDragDistance:
382 ret = QCommonStyle::pixelMetric(PM_MaximumDragDistance, opt, widget);
391 case PM_SliderControlThickness:
392 if (
const QStyleOptionSlider *sl = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
393 int space = (sl->orientation == Qt::Horizontal) ? sl->rect.height() : sl->rect.width();
394 int ticks = sl->tickPosition;
396 if (ticks & QSlider::TicksAbove)
398 if (ticks & QSlider::TicksBelow)
406 if (ticks != QSlider::TicksBothSides && ticks != QSlider::NoTicks)
407 thick += proxy()->pixelMetric(PM_SliderLength, sl, widget) / 4;
411 thick += (space * 2) / (n + 2);
417 case PM_IconViewIconSize:
418 ret = proxy()->pixelMetric(PM_LargeIconSize, opt, widget);
421 case PM_SplitterWidth:
422 ret = QStyleHelper::dpiScaled(4, opt);
426 ret = QCommonStyle::pixelMetric(pm, opt, widget);
434
435
436QPixmap QWindowsStyle::standardPixmap(StandardPixmap standardPixmap,
const QStyleOption *opt,
437 const QWidget *widget)
const
439 return QCommonStyle::standardPixmap(standardPixmap, opt, widget);
443int QWindowsStyle::styleHint(StyleHint hint,
const QStyleOption *opt,
const QWidget *widget,
444 QStyleHintReturn *returnData)
const
449 case SH_EtchDisabledText: {
450 const QPalette pal = opt ? opt->palette
451 : widget ? widget->palette()
453 ret = pal.window().color().lightness() > pal.text().color().lightness()
457 case SH_Slider_SnapToValue:
458 case SH_PrintDialog_RightAlignButtons:
459 case SH_FontDialog_SelectAssociatedText:
460 case SH_Menu_AllowActiveAndDisabled:
461 case SH_MenuBar_AltKeyNavigation:
462 case SH_MenuBar_MouseTracking:
463 case SH_Menu_MouseTracking:
464 case SH_ComboBox_ListMouseTracking_Current:
465 case SH_Slider_StopMouseOverSlider:
466 case SH_MainWindow_SpaceBelowMenuBar:
470 case SH_ItemView_ShowDecorationSelected:
471#if QT_CONFIG(listview)
472 if (qobject_cast<
const QListView*>(widget))
476 case SH_ItemView_ChangeHighlightOnFocus:
479 case SH_ToolBox_SelectedPageTitleBold:
484 case SH_UnderlineShortcut:
488 SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &cues, 0);
491 Q_D(
const QWindowsStyle);
492 if (!ret && widget && d) {
493#if QT_CONFIG(menubar)
494 const QMenuBar *menuBar = qobject_cast<
const QMenuBar *>(widget);
495 if (!menuBar && qobject_cast<
const QMenu *>(widget)) {
496 QWidget *w = QApplication::activeWindow();
497 if (w && w != widget)
498 menuBar = w->findChild<QMenuBar *>();
502 if (menuBar->d_func()->keyboardState || d->altDown())
507 if (d->hasSeenAlt(widget)) {
511#if QT_CONFIG(accessibility)
512 if (!ret && opt && opt->type == QStyleOption::SO_MenuItem
513 && QStyleHelper::isInstanceOf(opt->styleObject, QAccessible::MenuItem)
514 && opt->styleObject->property(
"_q_showUnderlined").toBool())
520 case SH_Menu_SubMenuSloppyCloseTimeout:
521 case SH_Menu_SubMenuPopupDelay: {
524 if (SystemParametersInfo(SPI_GETMENUSHOWDELAY, 0, &delay, 0))
531#if QT_CONFIG(rubberband)
532 case SH_RubberBand_Mask:
533 if (
const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<
const QStyleOptionRubberBand *>(opt)) {
535 if (rbOpt->shape == QRubberBand::Rectangle) {
537 if (QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(returnData)) {
538 mask->region = opt->rect;
540 if (widget && widget->isWindow())
542 mask->region -= opt->rect.adjusted(size, size, -size, -size);
550 ret = QWizard::ModernStyle;
553 case SH_ItemView_ArrowKeysNavigateIntoChildren:
556 case SH_DialogButtonBox_ButtonsHaveIcons:
560 ret = QCommonStyle::styleHint(hint, opt, widget, returnData);
567void QWindowsStyle::drawPrimitive(PrimitiveElement pe,
const QStyleOption *opt, QPainter *p,
568 const QWidget *w)
const
571 bool doRestore =
false;
574#if QT_CONFIG(toolbar)
575 case PE_IndicatorToolBarSeparator: {
576 QPainterStateGuard psg(p);
577 const QRect &rect = opt->rect;
578 constexpr int margin = 2;
579 if (opt->state & State_Horizontal){
580 const int offset = rect.width() / 2;
581 const auto &tl = rect.topLeft();
582 const auto &bl = rect.bottomLeft();
583 p->setPen(opt->palette.dark().color());
584 p->drawLine(QLine(bl.x() + offset, bl.y() - margin,
585 tl.x() + offset, tl.y() + margin));
586 p->setPen(opt->palette.light().color());
587 p->drawLine(QLine(bl.x() + offset + 1, bl.y() - margin,
588 tl.x() + offset + 1, tl.y() + margin));
591 const int offset = rect.height() / 2;
592 const auto &tl = rect.topLeft();
593 const auto &tr = rect.topRight();
594 p->setPen(opt->palette.dark().color());
595 p->drawLine(QLine(tl.x() + margin, tl.y() + offset,
596 tr.x() - margin, tr.y() + offset));
597 p->setPen(opt->palette.light().color());
598 p->drawLine(QLine(tl.x() + margin, tl.y() + offset + 1,
599 tr.x() - margin, tr.y() + offset + 1));
603 case PE_IndicatorToolBarHandle: {
604 QPainterStateGuard psg(p);
605 p->translate(opt->rect.x(), opt->rect.y());
606 if (opt->state & State_Horizontal) {
607 if (opt->rect.height() > 4) {
608 int x = opt->rect.width() / 2 - 4;
609 if (opt->direction == Qt::RightToLeft)
611 qDrawShadePanel(p, x, 2, 3, opt->rect.height() - 4,
612 opt->palette,
false, 1,
nullptr);
613 qDrawShadePanel(p, x + 3, 2, 3, opt->rect.height() - 4,
614 opt->palette,
false, 1,
nullptr);
617 if (opt->rect.width() > 4) {
618 int y = opt->rect.height() / 2 - 4;
619 qDrawShadePanel(p, 2, y, opt->rect.width() - 4, 3,
620 opt->palette,
false, 1,
nullptr);
621 qDrawShadePanel(p, 2, y + 3, opt->rect.width() - 4, 3,
622 opt->palette,
false, 1,
nullptr);
628 case PE_FrameButtonTool:
629 case PE_PanelButtonTool: {
630 QPen oldPen = p->pen();
631#if QT_CONFIG(dockwidget)
632 if (w && w->inherits(
"QDockWidgetTitleButton")) {
633 if (
const QWidget *dw = w->parentWidget())
635 qDrawWinButton(p, opt->rect.adjusted(1, 1, 0, 0), opt->palette, opt->state & (State_Sunken | State_On),
636 &opt->palette.button());
644 bool panel = (pe == PE_PanelButtonTool);
645 if ((!(opt->state & State_Sunken ))
646 && (!(opt->state & State_Enabled)
647 || !(opt->state & State_MouseOver && opt->state & State_AutoRaise))
648 && (opt->state & State_On)) {
649 fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
652 fill = opt->palette.brush(QPalette::Button);
656 if (opt->state & (State_Raised | State_Sunken | State_On)) {
657 if (opt->state & State_AutoRaise) {
658 if (opt->state & (State_Enabled | State_Sunken | State_On)){
660 qDrawShadePanel(p, opt->rect, opt->palette,
661 opt->state & (State_Sunken | State_On), 1, &fill);
663 qDrawShadeRect(p, opt->rect, opt->palette,
664 opt->state & (State_Sunken | State_On), 1);
667 p->setPen(opt->palette.button().color());
668 p->drawRect(opt->rect.adjusted(1,1,-2,-2));
671 qDrawWinButton(p, opt->rect, opt->palette,
672 opt->state & (State_Sunken | State_On), panel ? &fill :
nullptr);
675 p->fillRect(opt->rect, fill);
679 case PE_PanelButtonCommand:
680 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
682 State flags = opt->state;
683 QPalette pal = opt->palette;
685 if (! (flags & State_Sunken) && (flags & State_On))
686 fill = QBrush(pal.light().color(), Qt::Dense4Pattern);
688 fill = pal.brush(QPalette::Button);
690 if (btn->features & QStyleOptionButton::DefaultButton && flags & State_Sunken) {
691 p->setPen(pal.dark().color());
693 p->drawRect(r.adjusted(0, 0, -1, -1));
694 }
else if (flags & (State_Raised | State_On | State_Sunken)) {
695 qDrawWinButton(p, r, pal, flags & (State_Sunken | State_On),
698 p->fillRect(r, fill);
702 case PE_FrameDefaultButton: {
703 QPen oldPen = p->pen();
704 p->setPen(QPen(opt->palette.shadow().color(), 0));
705 QRectF rect = opt->rect;
706 const qreal dpi = QStyleHelper::dpi(opt);
707 const qreal topLevelAdjustment = QStyleHelper::dpiScaled(0.5, dpi);
708 const qreal bottomRightAdjustment = QStyleHelper::dpiScaled(-1.5, dpi);
709 rect.adjust(topLevelAdjustment, topLevelAdjustment,
710 bottomRightAdjustment, bottomRightAdjustment);
715 case PE_IndicatorCheckBox: {
717 if (opt->state & State_NoChange)
718 fill = QBrush(opt->palette.base().color(), Qt::Dense4Pattern);
719 else if (opt->state & State_Sunken)
720 fill = opt->palette.button();
721 else if (opt->state & State_Enabled)
722 fill = opt->palette.base();
724 fill = opt->palette.window();
727 qDrawWinPanel(p, opt->rect, opt->palette,
true, &fill);
728 if (opt->state & State_NoChange)
729 p->setPen(opt->palette.dark().color());
731 p->setPen(opt->palette.text().color());
734 case PE_IndicatorItemViewItemCheck:
739#if QT_CONFIG(itemviews)
740 if (pe == PE_IndicatorItemViewItemCheck) {
741 const QStyleOptionViewItem *itemViewOpt = qstyleoption_cast<
const QStyleOptionViewItem *>(opt);
742 p->setPen(itemViewOpt
743 && itemViewOpt->showDecorationSelected
744 && opt->state & State_Selected
745 ? opt->palette.highlightedText().color()
746 : opt->palette.text().color());
747 if (opt->state & State_NoChange)
748 p->setBrush(opt->palette.brush(QPalette::Button));
749 p->drawRect(opt->rect.x() + 1, opt->rect.y() + 1, opt->rect.width() - 2, opt->rect.height() - 2);
752 if (!(opt->state & State_Off)) {
753 std::array<QPointF, 6> points;
754 qreal scaleh = opt->rect.width() / 12.0;
755 qreal scalev = opt->rect.height() / 12.0;
756 points[0] = { opt->rect.x() + qreal(3.5) * scaleh, opt->rect.y() + qreal(5.5) * scalev };
757 points[1] = { points[0].x(), points[0].y() + 2 * scalev };
758 points[2] = { points[1].x() + 2 * scaleh, points[1].y() + 2 * scalev };
759 points[3] = { points[2].x() + 4 * scaleh, points[2].y() - 4 * scalev };
760 points[4] = { points[3].x(), points[3].y() - 2 * scalev };
761 points[5] = { points[4].x() - 4 * scaleh, points[4].y() + 4 * scalev };
762 p->setPen(QPen(opt->palette.text().color(), 0));
763 p->setBrush(opt->palette.text());
764 p->drawPolygon(points.data(),
static_cast<
int>(points.size()));
769 case PE_FrameFocusRect:
770 if (
const QStyleOptionFocusRect *fropt = qstyleoption_cast<
const QStyleOptionFocusRect *>(opt)) {
772 if (!(fropt->state & State_KeyboardFocusChange) && !proxy()->styleHint(SH_UnderlineShortcut, opt, w))
776 p->setBackgroundMode(Qt::TransparentMode);
777 QColor bg_col = fropt->backgroundColor;
778 if (!bg_col.isValid())
779 bg_col = p->background().color();
781 QColor patternCol((bg_col.red() ^ 0xff) & 0xff,
782 (bg_col.green() ^ 0xff) & 0xff,
783 (bg_col.blue() ^ 0xff) & 0xff);
784 p->setBrush(QBrush(patternCol, Qt::Dense4Pattern));
785 p->setBrushOrigin(r.topLeft());
786 p->setPen(Qt::NoPen);
787 p->drawRect(r.left(), r.top(), r.width(), 1);
788 p->drawRect(r.left(), r.bottom(), r.width(), 1);
789 p->drawRect(r.left(), r.top(), 1, r.height());
790 p->drawRect(r.right(), r.top(), 1, r.height());
794 case PE_IndicatorRadioButton:
798 p->setRenderHint(QPainter::Antialiasing,
true);
800 QPointF circleCenter = r.center() + QPoint(1, 1);
801 qreal radius = (r.width() + (r.width() + 1) % 2) / 2.0 - 1;
804 path1.addEllipse(circleCenter, radius, radius);
807 path2.addEllipse(circleCenter, radius, radius);
810 path3.addEllipse(circleCenter, radius, radius);
813 path4.addEllipse(circleCenter, radius, radius);
815 QPolygon topLeftPol, bottomRightPol;
816 topLeftPol.setPoints(3, r.x(), r.y(), r.x(), r.y() + r.height(), r.x() + r.width(), r.y());
817 bottomRightPol.setPoints(3, r.x(), r.y() + r.height(), r.x() + r.width(), r.y() + r.height(), r.x() + r.width(), r.y());
819 p->setClipRegion(QRegion(topLeftPol));
820 p->setPen(opt->palette.dark().color());
821 p->setBrush(opt->palette.dark());
823 p->setPen(opt->palette.shadow().color());
824 p->setBrush(opt->palette.shadow());
827 p->setClipRegion(QRegion(bottomRightPol));
828 p->setPen(opt->palette.light().color());
829 p->setBrush(opt->palette.light());
831 p->setPen(opt->palette.midlight().color());
832 p->setBrush(opt->palette.midlight());
835 QColor fillColor = ((opt->state & State_Sunken) || !(opt->state & State_Enabled)) ?
836 opt->palette.button().color() : opt->palette.base().color();
838 p->setClipping(
false);
839 p->setPen(fillColor);
840 p->setBrush(fillColor);
843 if (opt->state & State_On) {
844 p->setPen(opt->palette.text().color());
845 p->setBrush(opt->palette.text());
853 if (w && w->inherits(
"QComboBoxPrivateContainer")){
854 QStyleOption copy = *opt;
855 copy.state |= State_Raised;
856 proxy()->drawPrimitive(PE_PanelMenu, ©, p, w);
861 if (
const QStyleOptionFrame *frame = qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
862 if (frame->lineWidth == 2 || pe == PE_Frame) {
863 QPalette popupPal = frame->palette;
864 if (pe == PE_FrameMenu) {
865 popupPal.setColor(QPalette::Light, frame->palette.window().color());
866 popupPal.setColor(QPalette::Midlight, frame->palette.light().color());
868 if (pe == PE_Frame && (frame->state & State_Raised))
869 qDrawWinButton(p, frame->rect, popupPal, frame->state & State_Sunken);
870 else if (pe == PE_Frame && (frame->state & State_Sunken))
872 popupPal.setColor(QPalette::Midlight, frame->palette.window().color());
873 qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken);
876 qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken);
878 QCommonStyle::drawPrimitive(pe, opt, p, w);
881 QPalette popupPal = opt->palette;
882 p->drawRect(opt->rect);
883 popupPal.setColor(QPalette::Light, opt->palette.window().color());
884 popupPal.setColor(QPalette::Midlight, opt->palette.light().color());
885 qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken);
889 case PE_FrameButtonBevel:
890 case PE_PanelButtonBevel: {
892 bool panel = pe != PE_FrameButtonBevel;
893 p->setBrushOrigin(opt->rect.topLeft());
894 if (!(opt->state & State_Sunken) && (opt->state & State_On))
895 fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
897 fill = opt->palette.brush(QPalette::Button);
899 if (opt->state & (State_Raised | State_On | State_Sunken)) {
900 qDrawWinButton(p, opt->rect, opt->palette, opt->state & (State_Sunken | State_On),
901 panel ? &fill :
nullptr);
904 p->fillRect(opt->rect, fill);
906 p->drawRect(opt->rect);
910 if (w && w->inherits(
"QComboBoxPrivateContainer")){
911 const QBrush menuBackground = opt->palette.base().color();
912 QColor borderColor = opt->palette.window().color();
913 qDrawPlainRect(p, opt->rect, borderColor, 1, &menuBackground);
915 QCommonStyle::drawPrimitive(pe, opt, p, w);
918 case PE_FrameWindow: {
919 QPalette popupPal = opt->palette;
920 popupPal.setColor(QPalette::Light, opt->palette.window().color());
921 popupPal.setColor(QPalette::Midlight, opt->palette.light().color());
922 qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken);
924#if QT_CONFIG(dockwidget)
925 case PE_IndicatorDockWidgetResizeHandle:
927 case PE_FrameDockWidget:
928 if (qstyleoption_cast<
const QStyleOptionFrame *>(opt)) {
929 proxy()->drawPrimitive(QStyle::PE_FrameWindow, opt, p, w);
934 case PE_FrameStatusBarItem:
935 qDrawShadePanel(p, opt->rect, opt->palette,
true, 1,
nullptr);
938 case PE_IndicatorProgressChunk:
940 bool vertical =
false, inverted =
false;
941 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
942 vertical = !(pb->state & QStyle::State_Horizontal);
943 inverted = pb->invertedAppearance;
947 int chunksize = proxy()->pixelMetric(PM_ProgressBarChunkWidth, opt, w) - space;
949 if (opt->rect.width() <= chunksize)
953 p->fillRect(opt->rect.x() + space, opt->rect.y(), opt->rect.width() - space, opt->rect.height(),
954 opt->palette.brush(QPalette::Highlight));
956 p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width() - space, opt->rect.height(),
957 opt->palette.brush(QPalette::Highlight));
959 if (opt->rect.height() <= chunksize)
963 p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width(), opt->rect.height() - space,
964 opt->palette.brush(QPalette::Highlight));
966 p->fillRect(opt->rect.x(), opt->rect.y() + space, opt->rect.width(), opt->rect.height() - space,
967 opt->palette.brush(QPalette::Highlight));
972 case PE_FrameTabWidget: {
973 qDrawWinButton(p, opt->rect, opt->palette,
false,
nullptr);
977 QCommonStyle::drawPrimitive(pe, opt, p, w);
982void QWindowsStyle::drawControl(ControlElement ce,
const QStyleOption *opt, QPainter *p,
983 const QWidget *widget)
const
986#if QT_CONFIG(rubberband)
988 if (qstyleoption_cast<
const QStyleOptionRubberBand *>(opt)) {
990 QPixmap tiledPixmap(16, 16);
991 QPainter pixmapPainter(&tiledPixmap);
992 pixmapPainter.setPen(Qt::NoPen);
993 pixmapPainter.setBrush(Qt::Dense4Pattern);
994 pixmapPainter.setBackground(Qt::white);
995 pixmapPainter.setBackgroundMode(Qt::OpaqueMode);
996 pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height());
998 tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage());
1000 QRect r = opt->rect;
1001 QStyleHintReturnMask mask;
1002 if (proxy()->styleHint(QStyle::SH_RubberBand_Mask, opt, widget, &mask))
1003 p->setClipRegion(mask.region);
1004 p->drawTiledPixmap(r.x(), r.y(), r.width(), r.height(), tiledPixmap);
1011#if QT_CONFIG(menu) && QT_CONFIG(mainwindow)
1012 case CE_MenuBarEmptyArea:
1013 if (widget && qobject_cast<
const QMainWindow *>(widget->parentWidget())) {
1014 p->fillRect(opt->rect, opt->palette.button());
1015 QPen oldPen = p->pen();
1016 p->setPen(opt->palette.dark().color());
1017 p->drawLine(opt->rect.bottomLeft(), opt->rect.bottomRight());
1024 if (
const QStyleOptionMenuItem *menuitem = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
1026 menuitem->rect.getRect(&x, &y, &w, &h);
1027 int tab = menuitem->reservedShortcutWidth;
1028 bool dis = !(menuitem->state & State_Enabled);
1029 bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
1030 ? menuitem->checked :
false;
1031 bool act = menuitem->state & State_Selected;
1034 int checkcol = qMax<
int>(menuitem->maxIconWidth, QWindowsStylePrivate::windowsCheckMarkWidth);
1036 QBrush fill = menuitem->palette.brush(act ? QPalette::Highlight : QPalette::Button);
1037 p->fillRect(menuitem->rect.adjusted(0, 0, -1, 0), fill);
1039 if (menuitem->menuItemType == QStyleOptionMenuItem::Separator){
1040 int yoff = y-1 + h / 2;
1041 p->setPen(menuitem->palette.dark().color());
1042 p->drawLine(x + 2, yoff, x + w - 4, yoff);
1043 p->setPen(menuitem->palette.light().color());
1044 p->drawLine(x + 2, yoff + 1, x + w - 4, yoff + 1);
1048 QRect vCheckRect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x(), menuitem->rect.y(), checkcol, menuitem->rect.height()));
1049 if (!menuitem->icon.isNull() && checked) {
1051 qDrawShadePanel(p, vCheckRect,
1052 menuitem->palette,
true, 1,
1053 &menuitem->palette.brush(QPalette::Button));
1055 QBrush fill(menuitem->palette.light().color(), Qt::Dense4Pattern);
1056 qDrawShadePanel(p, vCheckRect, menuitem->palette,
true, 1, &fill);
1059 p->fillRect(vCheckRect, menuitem->palette.brush(QPalette::Button));
1065 if (!menuitem->icon.isNull()) {
1066 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
1068 mode = QIcon::Active;
1069 const auto size = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
1070 const auto dpr = QStyleHelper::getDpr(p);
1071 const auto state = checked ? QIcon::On : QIcon::Off;
1072 const auto pixmap = menuitem->icon.pixmap(QSize(size, size), dpr, mode, state);
1073 QRect pmr(QPoint(0, 0), pixmap.deviceIndependentSize().toSize());
1074 pmr.moveCenter(vCheckRect.center());
1075 p->setPen(menuitem->palette.text().color());
1076 p->drawPixmap(pmr.topLeft(), pixmap);
1077 }
else if (checked) {
1078 QStyleOptionMenuItem newMi = *menuitem;
1079 newMi.state = State_None;
1081 newMi.state |= State_Enabled;
1083 newMi.state |= State_On | State_Selected;
1084 newMi.rect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x() + QWindowsStylePrivate::windowsItemFrame,
1085 menuitem->rect.y() + QWindowsStylePrivate::windowsItemFrame,
1086 checkcol - 2 * QWindowsStylePrivate::windowsItemFrame,
1087 menuitem->rect.height() - 2 * QWindowsStylePrivate::windowsItemFrame));
1088 proxy()->drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, widget);
1090 p->setPen(act ? menuitem->palette.highlightedText().color() : menuitem->palette.buttonText().color());
1094 discol = menuitem->palette.text().color();
1098 int xm =
int(QWindowsStylePrivate::windowsItemFrame) + checkcol +
int(QWindowsStylePrivate::windowsItemHMargin);
1099 int xpos = menuitem->rect.x() + xm;
1100 QRect textRect(xpos, y + QWindowsStylePrivate::windowsItemVMargin,
1101 w - xm - QWindowsStylePrivate::windowsRightBorder - tab + 1, h - 2 * QWindowsStylePrivate::windowsItemVMargin);
1102 QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
1103 QStringView s(menuitem->text);
1106 qsizetype t = s.indexOf(u'\t');
1107 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
1108 if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget))
1109 text_flags |= Qt::TextHideMnemonic;
1110 text_flags |= Qt::AlignLeft;
1112 QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
1113 QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
1114 const QString textToDraw = s.mid(t + 1).toString();
1115 if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, opt, widget)) {
1116 p->setPen(menuitem->palette.light().color());
1117 p->drawText(vShortcutRect.adjusted(1, 1, 1, 1), text_flags, textToDraw);
1120 p->drawText(vShortcutRect, text_flags, textToDraw);
1123 QFont font = menuitem->font;
1124 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
1127 const QString textToDraw = s.left(t).toString();
1128 if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, opt, widget)) {
1129 p->setPen(menuitem->palette.light().color());
1130 p->drawText(vTextRect.adjusted(1, 1, 1, 1), text_flags, textToDraw);
1133 p->drawText(vTextRect, text_flags, textToDraw);
1136 if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {
1137 int dim = (h - 2 * QWindowsStylePrivate::windowsItemFrame) / 2;
1138 PrimitiveElement arrow;
1139 arrow = (opt->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
1140 xpos = x + w - QWindowsStylePrivate::windowsArrowHMargin - QWindowsStylePrivate::windowsItemFrame - dim;
1141 QRect vSubMenuRect = visualRect(opt->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim));
1142 QStyleOptionMenuItem newMI = *menuitem;
1143 newMI.rect = vSubMenuRect;
1144 newMI.state = dis ? State_None : State_Enabled;
1146 newMI.palette.setColor(QPalette::ButtonText,
1147 newMI.palette.highlightedText().color());
1148 proxy()->drawPrimitive(arrow, &newMI, p, widget);
1154#if QT_CONFIG(menubar)
1155 case CE_MenuBarItem:
1156 if (
const QStyleOptionMenuItem *mbi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
1157 const bool active = mbi->state & State_Selected;
1158 const QBrush buttonBrush = mbi->palette.brush(QPalette::Button);
1159 QStyleOptionMenuItem newMbi = *mbi;
1160 p->fillRect(mbi->rect, buttonBrush);
1162 const bool hasFocus = mbi->state & State_HasFocus;
1163 const bool down = mbi->state & State_Sunken;
1164 QPainterStateGuard psg(p, QPainterStateGuard::InitialState::NoSave);
1167 p->setBrushOrigin(p->brushOriginF() + QPointF(1, 1));
1170 qDrawShadeRect(p, mbi->rect.x(), mbi->rect.y(), mbi->rect.width(),
1171 mbi->rect.height(), mbi->palette, active && down, 1, 0, &buttonBrush);
1173 newMbi.rect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, mbi, widget),
1174 proxy()->pixelMetric(PM_ButtonShiftVertical, mbi, widget));
1176 QCommonStyle::drawControl(ce, &newMbi, p, widget);
1180#if QT_CONFIG(tabbar)
1181 case CE_TabBarTabShape:
1182 if (
const QStyleOptionTab *tab = qstyleoption_cast<
const QStyleOptionTab *>(opt)) {
1183 bool rtlHorTabs = (tab->direction == Qt::RightToLeft
1184 && (tab->shape == QTabBar::RoundedNorth
1185 || tab->shape == QTabBar::RoundedSouth));
1186 bool selected = tab->state & State_Selected;
1187 bool lastTab = ((!rtlHorTabs && tab->position == QStyleOptionTab::End)
1189 && tab->position == QStyleOptionTab::Beginning));
1190 bool firstTab = ((!rtlHorTabs
1191 && tab->position == QStyleOptionTab::Beginning)
1193 && tab->position == QStyleOptionTab::End));
1194 bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
1195 bool previousSelected =
1197 && tab->selectedPosition == QStyleOptionTab::PreviousIsSelected)
1199 && tab->selectedPosition == QStyleOptionTab::NextIsSelected));
1202 && tab->selectedPosition == QStyleOptionTab::NextIsSelected)
1204 && tab->selectedPosition
1205 == QStyleOptionTab::PreviousIsSelected));
1206 int tabBarAlignment = proxy()->styleHint(SH_TabBar_Alignment, tab, widget);
1207 bool leftAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignLeft)
1209 && tabBarAlignment == Qt::AlignRight);
1211 bool rightAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignRight)
1213 && tabBarAlignment == Qt::AlignLeft);
1215 QColor light = tab->palette.light().color();
1216 QColor dark = tab->palette.dark().color();
1217 QColor shadow = tab->palette.shadow().color();
1218 int borderThinkness = proxy()->pixelMetric(PM_TabBarBaseOverlap, tab, widget);
1220 borderThinkness /= 2;
1221 QRect r2(opt->rect);
1223 int x2 = r2.right();
1225 int y2 = r2.bottom();
1226 switch (tab->shape) {
1228 QCommonStyle::drawControl(ce, tab, p, widget);
1230 case QTabBar::RoundedNorth: {
1233 x1 += onlyOne || firstTab ? borderThinkness : 0;
1234 x2 -= onlyOne || lastTab ? borderThinkness : 0;
1237 p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 2), tab->palette.window());
1241 p->fillRect(QRect(x1,y2-1,x2-x1,1), tab->palette.window());
1242 p->fillRect(QRect(x1,y2,x2-x1,1), tab->palette.window());
1245 if (firstTab || selected || onlyOne || !previousSelected) {
1247 p->drawLine(x1, y1 + 2, x1, y2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
1248 p->drawPoint(x1 + 1, y1 + 1);
1252 int beg = x1 + (previousSelected ? 0 : 2);
1253 int end = x2 - (nextSelected ? 0 : 2);
1255 p->drawLine(beg, y1, end, y1);
1258 if (lastTab || selected || onlyOne || !nextSelected) {
1260 p->drawLine(x2, y1 + 2, x2, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1261 p->drawPoint(x2 - 1, y1 + 1);
1263 p->drawLine(x2 - 1, y1 + 2, x2 - 1, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1266 case QTabBar::RoundedSouth: {
1269 x1 += firstTab ? borderThinkness : 0;
1270 x2 -= lastTab ? borderThinkness : 0;
1273 p->fillRect(QRect(x1 + 1, y1 + 2, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.window());
1277 p->fillRect(QRect(x1, y1 + 1, (x2 - 1)-x1, 1), tab->palette.window());
1278 p->fillRect(QRect(x1, y1, (x2 - 1)-x1, 1), tab->palette.window());
1281 if (firstTab || selected || onlyOne || !previousSelected) {
1283 p->drawLine(x1, y2 - 2, x1, y1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
1284 p->drawPoint(x1 + 1, y2 - 1);
1288 int beg = x1 + (previousSelected ? 0 : 2);
1289 int end = x2 - (nextSelected ? 0 : 2);
1291 p->drawLine(beg, y2, end, y2);
1293 p->drawLine(beg, y2 - 1, end, y2 - 1);
1296 if (lastTab || selected || onlyOne || !nextSelected) {
1298 p->drawLine(x2, y2 - 2, x2, y1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1299 p->drawPoint(x2 - 1, y2 - 1);
1301 p->drawLine(x2 - 1, y2 - 2, x2 - 1, y1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1304 case QTabBar::RoundedWest: {
1307 y1 += firstTab ? borderThinkness : 0;
1308 y2 -= lastTab ? borderThinkness : 0;
1311 p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 2, (y2 - y1) - 1), tab->palette.window());
1315 p->fillRect(QRect(x2 - 1, y1, 1, y2-y1), tab->palette.window());
1316 p->fillRect(QRect(x2, y1, 1, y2-y1), tab->palette.window());
1319 if (firstTab || selected || onlyOne || !previousSelected) {
1321 p->drawLine(x1 + 2, y1, x2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1);
1322 p->drawPoint(x1 + 1, y1 + 1);
1326 int beg = y1 + (previousSelected ? 0 : 2);
1327 int end = y2 - (nextSelected ? 0 : 2);
1329 p->drawLine(x1, beg, x1, end);
1332 if (lastTab || selected || onlyOne || !nextSelected) {
1334 p->drawLine(x1 + 3, y2, x2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2);
1335 p->drawPoint(x1 + 2, y2 - 1);
1337 p->drawLine(x1 + 3, y2 - 1, x2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2 - 1);
1338 p->drawPoint(x1 + 1, y2 - 1);
1339 p->drawPoint(x1 + 2, y2);
1342 case QTabBar::RoundedEast: {
1345 y1 += firstTab ? borderThinkness : 0;
1346 y2 -= lastTab ? borderThinkness : 0;
1349 p->fillRect(QRect(x1 + 2, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.window());
1353 p->fillRect(QRect(x1 + 1, y1, 1, (y2 - 1)-y1),tab->palette.window());
1354 p->fillRect(QRect(x1, y1, 1, (y2-1)-y1), tab->palette.window());
1357 if (firstTab || selected || onlyOne || !previousSelected) {
1359 p->drawLine(x2 - 2, y1, x1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1);
1360 p->drawPoint(x2 - 1, y1 + 1);
1364 int beg = y1 + (previousSelected ? 0 : 2);
1365 int end = y2 - (nextSelected ? 0 : 2);
1367 p->drawLine(x2, beg, x2, end);
1369 p->drawLine(x2 - 1, beg, x2 - 1, end);
1372 if (lastTab || selected || onlyOne || !nextSelected) {
1374 p->drawLine(x2 - 2, y2, x1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2);
1375 p->drawPoint(x2 - 1, y2 - 1);
1377 p->drawLine(x2 - 2, y2 - 1, x1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2 - 1);
1384 case CE_ToolBoxTabShape:
1385 qDrawShadePanel(p, opt->rect, opt->palette,
1386 opt->state & (State_Sunken | State_On), 1,
1387 &opt->palette.brush(QPalette::Button));
1389#if QT_CONFIG(splitter)
1391 p->eraseRect(opt->rect);
1394#if QT_CONFIG(scrollbar)
1395 case CE_ScrollBarSubLine:
1396 case CE_ScrollBarAddLine: {
1397 if ((opt->state & State_Sunken)) {
1398 p->setPen(opt->palette.dark().color());
1399 p->setBrush(opt->palette.brush(QPalette::Button));
1400 p->drawRect(opt->rect.adjusted(0, 0, -1, -1));
1402 QStyleOption buttonOpt = *opt;
1403 if (!(buttonOpt.state & State_Sunken))
1404 buttonOpt.state |= State_Raised;
1405 QPalette pal(opt->palette);
1406 pal.setColor(QPalette::Button, opt->palette.light().color());
1407 pal.setColor(QPalette::Light, opt->palette.button().color());
1408 qDrawWinButton(p, opt->rect, pal, opt->state & (State_Sunken | State_On),
1409 &opt->palette.brush(QPalette::Button));
1411 PrimitiveElement arrow;
1412 if (opt->state & State_Horizontal) {
1413 if (ce == CE_ScrollBarAddLine)
1414 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
1416 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
1418 if (ce == CE_ScrollBarAddLine)
1419 arrow = PE_IndicatorArrowDown;
1421 arrow = PE_IndicatorArrowUp;
1423 QStyleOption arrowOpt = *opt;
1424 arrowOpt.rect = opt->rect.adjusted(4, 4, -4, -4);
1425 proxy()->drawPrimitive(arrow, &arrowOpt, p, widget);
1427 case CE_ScrollBarAddPage:
1428 case CE_ScrollBarSubPage: {
1430 QBrush bg = p->background();
1431 Qt::BGMode bg_mode = p->backgroundMode();
1432 p->setPen(Qt::NoPen);
1433 p->setBackgroundMode(Qt::OpaqueMode);
1435 if (opt->state & State_Sunken) {
1436 br = QBrush(opt->palette.shadow().color(), Qt::Dense4Pattern);
1437 p->setBackground(opt->palette.dark().color());
1440 const QBrush paletteBrush = opt->palette.brush(QPalette::Light);
1441 if (paletteBrush.style() == Qt::TexturePattern) {
1442 if (qHasPixmapTexture(paletteBrush))
1443 br = QBrush(paletteBrush.texture());
1445 br = QBrush(paletteBrush.textureImage());
1447 br = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
1448 p->setBackground(opt->palette.window().color());
1451 p->drawRect(opt->rect);
1452 p->setBackground(bg);
1453 p->setBackgroundMode(bg_mode);
1455 case CE_ScrollBarSlider:
1456 if (!(opt->state & State_Enabled)) {
1458 const QBrush paletteBrush = opt->palette.brush(QPalette::Light);
1459 if (paletteBrush.style() == Qt::TexturePattern) {
1460 if (qHasPixmapTexture(paletteBrush))
1461 br = QBrush(paletteBrush.texture());
1463 br = QBrush(paletteBrush.textureImage());
1465 br = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
1466 p->setPen(Qt::NoPen);
1468 p->setBackgroundMode(Qt::OpaqueMode);
1469 p->drawRect(opt->rect);
1471 QStyleOptionButton buttonOpt;
1472 buttonOpt.QStyleOption::operator=(*opt);
1473 buttonOpt.state = State_Enabled | State_Raised;
1475 QPalette pal(opt->palette);
1476 pal.setColor(QPalette::Button, opt->palette.light().color());
1477 pal.setColor(QPalette::Light, opt->palette.button().color());
1478 qDrawWinButton(p, opt->rect, pal,
false, &opt->palette.brush(QPalette::Button));
1482 case CE_HeaderSection: {
1484 if (opt->state & State_On)
1485 fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
1487 fill = opt->palette.brush(QPalette::Button);
1489 if (opt->state & (State_Raised | State_Sunken)) {
1490 qDrawWinButton(p, opt->rect, opt->palette, opt->state & State_Sunken, &fill);
1492 p->fillRect(opt->rect, fill);
1495#if QT_CONFIG(toolbar)
1497 if (
const QStyleOptionToolBar *toolbar = qstyleoption_cast<
const QStyleOptionToolBar *>(opt)) {
1499 if (!(widget && qobject_cast<
const QMainWindow*> (widget->parentWidget())))
1502 QRect rect = opt->rect;
1503 bool paintLeftBorder =
true;
1504 bool paintRightBorder =
true;
1505 bool paintBottomBorder =
true;
1507 switch (toolbar->toolBarArea){
1508 case Qt::BottomToolBarArea :
1509 switch(toolbar->positionOfLine){
1510 case QStyleOptionToolBar::Beginning:
1511 case QStyleOptionToolBar::OnlyOne:
1512 paintBottomBorder =
false;
1518 case Qt::TopToolBarArea :
1519 switch(toolbar->positionWithinLine){
1520 case QStyleOptionToolBar::Beginning:
1521 paintLeftBorder =
false;
1523 case QStyleOptionToolBar::End:
1524 paintRightBorder =
false;
1526 case QStyleOptionToolBar::OnlyOne:
1527 paintRightBorder =
false;
1528 paintLeftBorder =
false;
1533 if (opt->direction == Qt::RightToLeft)
1534 std::swap(paintLeftBorder, paintRightBorder);
1536 case Qt::RightToolBarArea :
1537 switch (toolbar->positionOfLine){
1538 case QStyleOptionToolBar::Beginning:
1539 case QStyleOptionToolBar::OnlyOne:
1540 paintRightBorder =
false;
1546 case Qt::LeftToolBarArea :
1547 switch (toolbar->positionOfLine){
1548 case QStyleOptionToolBar::Beginning:
1549 case QStyleOptionToolBar::OnlyOne:
1550 paintLeftBorder =
false;
1562 p->setPen(opt->palette.light().color());
1563 p->drawLine(rect.topLeft(), rect.topRight());
1565 if (paintLeftBorder){
1566 p->setPen(opt->palette.light().color());
1567 p->drawLine(rect.topLeft(), rect.bottomLeft());
1570 if (paintRightBorder){
1571 p->setPen(opt->palette.dark().color());
1572 p->drawLine(rect.topRight(), rect.bottomRight());
1575 if (paintBottomBorder){
1576 p->setPen(opt->palette.dark().color());
1577 p->drawLine(rect.bottomLeft(), rect.bottomRight());
1585 case CE_ProgressBarContents:
1586 if (
const QStyleOptionProgressBar *pb = qstyleoption_cast<
const QStyleOptionProgressBar *>(opt)) {
1587 QRect rect = pb->rect;
1588 if (!rect.isValid())
1591 const bool vertical = !(pb->state & QStyle::State_Horizontal);
1592 const bool inverted = pb->invertedAppearance;
1596 rect = QRect(rect.y(), rect.x(), rect.height(), rect.width());
1598 m.translate(0, -(rect.height() + rect.y()*2));
1600 QPalette pal2 = pb->palette;
1602 if (pal2.highlight() == pal2.window())
1603 pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active,
1604 QPalette::Highlight));
1605 bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical);
1608 int w = rect.width();
1609 Q_D(
const QWindowsStyle);
1610 if (pb->minimum == 0 && pb->maximum == 0) {
1611 const int unit_width = proxy()->pixelMetric(PM_ProgressBarChunkWidth, pb, widget);
1612 QStyleOptionProgressBar pbBits = *pb;
1613 Q_ASSERT(unit_width >0);
1616 pbBits.palette = pal2;
1619 int chunkCount = w / unit_width + 1;
1620#if QT_CONFIG(animation)
1621 if (QProgressStyleAnimation *animation = qobject_cast<QProgressStyleAnimation*>(d->animation(opt->styleObject)))
1622 step = (animation->animationStep() / 3) % chunkCount;
1624 d->startAnimation(
new QProgressStyleAnimation(d->animationFps, opt->styleObject));
1628 int chunksInRow = 5;
1629 int myY = pbBits.rect.y();
1630 int myHeight = pbBits.rect.height();
1631 int chunksToDraw = chunksInRow;
1633 if (step > chunkCount - 5)chunksToDraw = (chunkCount - step);
1635 p->setClipRect(m.mapRect(QRectF(rect)).toRect());
1637 int x0 = reverse ? rect.left() + rect.width() - unit_width*(step) - unit_width : rect.left() + unit_width * step;
1640 for (
int i = 0; i < chunksToDraw ; ++i) {
1641 pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);
1642 pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();
1643 proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
1644 x += reverse ? -unit_width : unit_width;
1647 if ( step > chunkCount-5){
1648 x0 = reverse ? rect.left() + rect.width() - unit_width : rect.left() ;
1650 int chunksToDraw = step - (chunkCount - chunksInRow);
1651 for (
int i = 0; i < chunksToDraw ; ++i) {
1652 pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);
1653 pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();
1654 proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
1655 x += reverse ? -unit_width : unit_width;
1661#if QT_CONFIG(animation)
1662 d->stopAnimation(opt->styleObject);
1664 QCommonStyle::drawControl(ce, opt, p, widget);
1669#if QT_CONFIG(dockwidget)
1670 case CE_DockWidgetTitle:
1672 if (
const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<
const QStyleOptionDockWidget *>(opt)) {
1673 Q_D(
const QWindowsStyle);
1675 const bool verticalTitleBar = dwOpt->verticalTitleBar;
1677 QRect rect = dwOpt->rect;
1680 if (verticalTitleBar) {
1684 p->translate(r.left(), r.top() + r.width());
1686 p->translate(-r.left(), -r.top());
1689 bool floating =
false;
1690 bool active = dwOpt->state & State_Active;
1691 QColor inactiveCaptionTextColor = d->inactiveCaptionText;
1692 if (dwOpt->movable) {
1696 if (opt->state & QStyle::State_Window) {
1699 left = d->activeCaptionColor;
1700 right = d->activeGradientCaptionColor;
1702 left = d->inactiveCaptionColor;
1703 right = d->inactiveGradientCaptionColor;
1705 QBrush fillBrush(left);
1706 if (left != right) {
1707 QPoint p1(r.x(), r.top() + r.height()/2);
1708 QPoint p2(rect.right(), r.top() + r.height()/2);
1709 QLinearGradient lg(p1, p2);
1710 lg.setColorAt(0, left);
1711 lg.setColorAt(1, right);
1714 p->fillRect(r.adjusted(0, 0, 0, -3), fillBrush);
1717 if (!dwOpt->title.isEmpty()) {
1718 QFont oldFont = p->font();
1720 QFont font = oldFont;
1724 QPalette palette = dwOpt->palette;
1725 palette.setColor(QPalette::Window, inactiveCaptionTextColor);
1726 QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, opt, widget);
1727 if (verticalTitleBar) {
1728 titleRect = QRect(r.left() + rect.bottom()
1729 - titleRect.bottom(),
1730 r.top() + titleRect.left() - rect.left(),
1731 titleRect.height(), titleRect.width());
1733 proxy()->drawItemText(p, titleRect,
1734 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextHideMnemonic, palette,
1735 dwOpt->state & State_Enabled, dwOpt->title,
1736 floating ? (active ? QPalette::BrightText : QPalette::Window) : QPalette::WindowText);
1737 p->setFont(oldFont);
1739 if (verticalTitleBar)
1744#if QT_CONFIG(combobox)
1745 case CE_ComboBoxLabel:
1746 if (
const QStyleOptionComboBox *cb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
1747 if (cb->state & State_HasFocus) {
1748 p->setPen(cb->palette.highlightedText().color());
1749 p->setBackground(cb->palette.highlight());
1751 p->setPen(cb->palette.text().color());
1752 p->setBackground(cb->palette.window());
1755 QCommonStyle::drawControl(ce, opt, p, widget);
1759 QCommonStyle::drawControl(ce, opt, p, widget);
1764QRect QWindowsStyle::subElementRect(SubElement sr,
const QStyleOption *opt,
const QWidget *w)
const
1768 case SE_SliderFocusRect:
1769 case SE_ToolBoxTabContents:
1770 r = visualRect(opt->direction, opt->rect, opt->rect);
1772 case SE_DockWidgetTitleBarText: {
1773 r = QCommonStyle::subElementRect(sr, opt, w);
1774 const QStyleOptionDockWidget *dwOpt
1775 = qstyleoption_cast<
const QStyleOptionDockWidget*>(opt);
1776 const bool verticalTitleBar = dwOpt && dwOpt->verticalTitleBar;
1777 int m = proxy()->pixelMetric(PM_DockWidgetTitleMargin, opt, w);
1778 if (verticalTitleBar) {
1779 r.adjust(0, 0, 0, -m);
1781 if (opt->direction == Qt::LeftToRight)
1782 r.adjust(m, 0, 0, 0);
1784 r.adjust(0, 0, -m, 0);
1788 case SE_ProgressBarContents:
1789 r = QCommonStyle::subElementRect(SE_ProgressBarGroove, opt, w);
1790 r.adjust(3, 3, -3, -3);
1793 r = QCommonStyle::subElementRect(sr, opt, w);
1800void QWindowsStyle::drawComplexControl(ComplexControl cc,
const QStyleOptionComplex *opt,
1801 QPainter *p,
const QWidget *widget)
const
1804#if QT_CONFIG(slider)
1806 if (
const QStyleOptionSlider *slider = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
1807 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
1808 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
1809 int ticks = slider->tickPosition;
1810 QRect groove = proxy()->subControlRect(CC_Slider, slider, SC_SliderGroove, widget);
1811 QRect handle = proxy()->subControlRect(CC_Slider, slider, SC_SliderHandle, widget);
1813 if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {
1814 int mid = thickness / 2;
1816 if (ticks & QSlider::TicksAbove)
1818 if (ticks & QSlider::TicksBelow)
1821 p->setPen(slider->palette.shadow().color());
1822 if (slider->orientation == Qt::Horizontal) {
1823 qDrawWinPanel(p, groove.x(), groove.y() + mid - 2,
1824 groove.width(), 4, slider->palette,
true);
1825 p->drawLine(groove.x() + 1, groove.y() + mid - 1,
1826 groove.x() + groove.width() - 3, groove.y() + mid - 1);
1828 qDrawWinPanel(p, groove.x() + mid - 2, groove.y(),
1829 4, groove.height(), slider->palette,
true);
1830 p->drawLine(groove.x() + mid - 1, groove.y() + 1,
1831 groove.x() + mid - 1, groove.y() + groove.height() - 3);
1835 if (slider->subControls & SC_SliderTickmarks) {
1836 QStyleOptionSlider tmpSlider = *slider;
1837 tmpSlider.subControls = SC_SliderTickmarks;
1838 QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget);
1841 if (slider->subControls & SC_SliderHandle) {
1851 const QColor c0 = slider->palette.shadow().color();
1852 const QColor c1 = slider->palette.dark().color();
1854 const QColor c3 = slider->palette.midlight().color();
1855 const QColor c4 = slider->palette.light().color();
1858 if (slider->state & State_Enabled) {
1859 handleBrush = slider->palette.color(QPalette::Button);
1861 handleBrush = QBrush(slider->palette.color(QPalette::Button),
1866 int x = handle.x(), y = handle.y(),
1867 wi = handle.width(), he = handle.height();
1874 Qt::Orientation orient = slider->orientation;
1875 bool tickAbove = slider->tickPosition == QSlider::TicksAbove;
1876 bool tickBelow = slider->tickPosition == QSlider::TicksBelow;
1878 if (slider->state & State_HasFocus) {
1879 QStyleOptionFocusRect fropt;
1880 fropt.QStyleOption::operator=(*slider);
1881 fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
1882 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
1885 if ((tickAbove && tickBelow) || (!tickAbove && !tickBelow)) {
1886 Qt::BGMode oldMode = p->backgroundMode();
1887 p->setBackgroundMode(Qt::OpaqueMode);
1888 qDrawWinButton(p, QRect(x, y, wi, he), slider->palette,
false,
1890 p->setBackgroundMode(oldMode);
1894 QSliderDirection dir;
1896 if (orient == Qt::Horizontal)
1897 dir = tickAbove ? SlUp : SlDown;
1899 dir = tickAbove ? SlLeft : SlRight;
1901 std::array<QPoint, 5> points;
1906 d = (wi + 1) / 2 - 1;
1907 points = {QPoint(x1, y1), QPoint(x1, y2), QPoint(x2, y2),
1908 QPoint(x2, y1), QPoint(x1 + d, y1 - d)};
1912 d = (wi + 1) / 2 - 1;
1913 points = {QPoint(x1, y1), QPoint(x1, y2), QPoint(x1 + d, y2 + d),
1914 QPoint(x2, y2), QPoint(x2, y1)};
1917 d = (he + 1) / 2 - 1;
1919 points = {QPoint(x1, y1), QPoint(x1 - d, y1 + d), QPoint(x1,y2),
1920 QPoint(x2, y2), QPoint(x2, y1)};
1923 d = (he + 1) / 2 - 1;
1925 points = {QPoint(x1, y1), QPoint(x1, y2), QPoint(x2, y2),
1926 QPoint(x2 + d, y1 + d), QPoint(x2, y1)};
1930 QBrush oldBrush = p->brush();
1931 p->setPen(Qt::NoPen);
1932 p->setBrush(handleBrush);
1933 Qt::BGMode oldMode = p->backgroundMode();
1934 p->setBackgroundMode(Qt::OpaqueMode);
1935 p->drawRect(x1, y1, x2-x1+1, y2-y1+1);
1936 p->drawPolygon(points.data(),
static_cast<
int>(points.size()));
1937 p->setBrush(oldBrush);
1938 p->setBackgroundMode(oldMode);
1942 p->drawLine(x1, y1, x2, y1);
1944 p->drawLine(x1, y1+1, x2, y1+1);
1946 if (dir != SlLeft) {
1948 p->drawLine(x1+1, y1+1, x1+1, y2);
1950 p->drawLine(x1, y1, x1, y2);
1952 if (dir != SlRight) {
1954 p->drawLine(x2, y1, x2, y2);
1956 p->drawLine(x2-1, y1+1, x2-1, y2-1);
1958 if (dir != SlDown) {
1960 p->drawLine(x1, y2, x2, y2);
1962 p->drawLine(x1+1, y2-1, x2-1, y2-1);
1968 p->drawLine(x1, y1, x1+d, y1-d);
1971 p->drawLine(x2, y1, x2-d, y1-d);
1974 p->drawLine(x1+1, y1, x1+1+d, y1-d);
1976 p->drawLine(x2-1, y1, x2-1-d, y1-d);
1980 p->drawLine(x1, y2, x1+d, y2+d);
1983 p->drawLine(x2, y2, x2-d, y2+d);
1986 p->drawLine(x1+1, y2, x1+1+d, y2+d);
1988 p->drawLine(x2-1, y2, x2-1-d, y2+d);
1992 p->drawLine(x1, y1, x1-d, y1+d);
1995 p->drawLine(x1, y2, x1-d, y2-d);
1998 p->drawLine(x1, y1+1, x1-d, y1+1+d);
2000 p->drawLine(x1, y2-1, x1-d, y2-1-d);
2004 p->drawLine(x2, y1, x2+d, y1+d);
2007 p->drawLine(x2, y2, x2+d, y2-d);
2010 p->drawLine(x2, y1+1, x2+d, y1+1+d);
2012 p->drawLine(x2, y2-1, x2+d, y2-1-d);
2019#if QT_CONFIG(scrollbar)
2021 if (
const QStyleOptionSlider *scrollbar = qstyleoption_cast<
const QStyleOptionSlider *>(opt)) {
2022 QStyleOptionSlider newScrollbar = *scrollbar;
2023 if (scrollbar->minimum == scrollbar->maximum)
2024 newScrollbar.state &= ~State_Enabled;
2025 QCommonStyle::drawComplexControl(cc, &newScrollbar, p, widget);
2029#if QT_CONFIG(combobox)
2031 if (
const QStyleOptionComboBox *cmb = qstyleoption_cast<
const QStyleOptionComboBox *>(opt)) {
2032 QBrush editBrush = cmb->palette.brush(QPalette::Button);
2033 if ((cmb->subControls & SC_ComboBoxFrame)) {
2035 QPalette shadePal = opt->palette;
2036 shadePal.setColor(QPalette::Midlight, shadePal.button().color());
2037 qDrawWinPanel(p, opt->rect, shadePal,
true, &editBrush);
2040 p->fillRect(opt->rect, editBrush);
2043 if (cmb->subControls & SC_ComboBoxArrow) {
2044 State flags = State_None;
2046 QRect ar = proxy()->subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget);
2047 bool sunkenArrow = cmb->activeSubControls == SC_ComboBoxArrow
2048 && cmb->state & State_Sunken;
2050 p->setPen(cmb->palette.dark().color());
2051 p->setBrush(cmb->palette.brush(QPalette::Button));
2052 p->drawRect(ar.adjusted(0,0,-1,-1));
2055 QPalette pal(cmb->palette);
2056 pal.setColor(QPalette::Button, cmb->palette.light().color());
2057 pal.setColor(QPalette::Light, cmb->palette.button().color());
2058 qDrawWinButton(p, ar, pal,
false,
2059 &cmb->palette.brush(QPalette::Button));
2062 ar.adjust(2, 2, -2, -2);
2063 if (opt->state & State_Enabled)
2064 flags |= State_Enabled;
2065 if (opt->state & State_HasFocus)
2066 flags |= State_HasFocus;
2069 flags |= State_Sunken;
2070 QStyleOption arrowOpt = *cmb;
2071 arrowOpt.rect = ar.adjusted(1, 1, -1, -1);
2072 arrowOpt.state = flags;
2073 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget);
2076 if (cmb->subControls & SC_ComboBoxEditField) {
2077 QRect re = proxy()->subControlRect(CC_ComboBox, cmb, SC_ComboBoxEditField, widget);
2078 if (cmb->state & State_HasFocus && !cmb->editable)
2079 p->fillRect(re.x(), re.y(), re.width(), re.height(),
2080 cmb->palette.brush(QPalette::Highlight));
2082 if (cmb->state & State_HasFocus) {
2083 p->setPen(cmb->palette.highlightedText().color());
2084 p->setBackground(cmb->palette.highlight());
2087 p->setPen(cmb->palette.text().color());
2088 p->setBackground(cmb->palette.window());
2091 if (cmb->state & State_HasFocus && !cmb->editable) {
2092 QStyleOptionFocusRect focus;
2093 focus.QStyleOption::operator=(*cmb);
2094 focus.rect = subElementRect(SE_ComboBoxFocusRect, cmb, widget);
2095 focus.state |= State_FocusAtBorder;
2096 focus.backgroundColor = cmb->palette.highlight().color();
2097 proxy()->drawPrimitive(PE_FrameFocusRect, &focus, p, widget);
2103#if QT_CONFIG(spinbox)
2105 if (
const QStyleOptionSpinBox *sb = qstyleoption_cast<
const QStyleOptionSpinBox *>(opt)) {
2106 QStyleOptionSpinBox copy = *sb;
2107 PrimitiveElement pe;
2108 bool enabled = opt->state & State_Enabled;
2109 if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
2110 QBrush editBrush = sb->palette.brush(QPalette::Base);
2111 QRect r = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxFrame, widget);
2112 QPalette shadePal = sb->palette;
2113 shadePal.setColor(QPalette::Midlight, shadePal.button().color());
2114 qDrawWinPanel(p, r, shadePal,
true, &editBrush);
2117 QPalette shadePal(opt->palette);
2118 shadePal.setColor(QPalette::Button, opt->palette.light().color());
2119 shadePal.setColor(QPalette::Light, opt->palette.button().color());
2121 if (sb->subControls & SC_SpinBoxUp) {
2122 copy.subControls = SC_SpinBoxUp;
2123 QPalette pal2 = sb->palette;
2124 if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled)) {
2125 pal2.setCurrentColorGroup(QPalette::Disabled);
2126 copy.state &= ~State_Enabled;
2129 copy.palette = pal2;
2131 if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken)) {
2132 copy.state |= State_On;
2133 copy.state |= State_Sunken;
2135 copy.state |= State_Raised;
2136 copy.state &= ~State_Sunken;
2138 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
2139 : PE_IndicatorSpinUp);
2141 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget);
2142 qDrawWinButton(p, copy.rect, shadePal, copy.state & (State_Sunken | State_On),
2143 ©.palette.brush(QPalette::Button));
2144 copy.rect.adjust(4, 1, -5, -1);
2145 if ((!enabled || !(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled))
2146 && proxy()->styleHint(SH_EtchDisabledText, opt, widget) )
2148 QStyleOptionSpinBox lightCopy = copy;
2149 lightCopy.rect.adjust(1, 1, 1, 1);
2150 lightCopy.palette.setBrush(QPalette::ButtonText, copy.palette.light());
2151 proxy()->drawPrimitive(pe, &lightCopy, p, widget);
2153 proxy()->drawPrimitive(pe, ©, p, widget);
2156 if (sb->subControls & SC_SpinBoxDown) {
2157 copy.subControls = SC_SpinBoxDown;
2158 copy.state = sb->state;
2159 QPalette pal2 = sb->palette;
2160 if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled)) {
2161 pal2.setCurrentColorGroup(QPalette::Disabled);
2162 copy.state &= ~State_Enabled;
2164 copy.palette = pal2;
2166 if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken)) {
2167 copy.state |= State_On;
2168 copy.state |= State_Sunken;
2170 copy.state |= State_Raised;
2171 copy.state &= ~State_Sunken;
2173 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
2174 : PE_IndicatorSpinDown);
2176 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget);
2177 qDrawWinButton(p, copy.rect, shadePal, copy.state & (State_Sunken | State_On),
2178 ©.palette.brush(QPalette::Button));
2179 copy.rect.adjust(4, 0, -5, -1);
2180 if ((!enabled || !(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled))
2181 && proxy()->styleHint(SH_EtchDisabledText, opt, widget) )
2183 QStyleOptionSpinBox lightCopy = copy;
2184 lightCopy.rect.adjust(1, 1, 1, 1);
2185 lightCopy.palette.setBrush(QPalette::ButtonText, copy.palette.light());
2186 proxy()->drawPrimitive(pe, &lightCopy, p, widget);
2188 proxy()->drawPrimitive(pe, ©, p, widget);
2195 QCommonStyle::drawComplexControl(cc, opt, p, widget);
2200QSize QWindowsStyle::sizeFromContents(ContentsType ct,
const QStyleOption *opt,
2201 const QSize &csz,
const QWidget *widget)
const
2206 if (
const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt)) {
2207 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2211 if (btn->features & QStyleOptionButton::AutoDefaultButton)
2212 defwidth = 2 * proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
2213 const qreal dpi = QStyleHelper::dpi(opt);
2214 int minwidth =
int(QStyleHelper::dpiScaled(75, dpi));
2215 int minheight =
int(QStyleHelper::dpiScaled(23, dpi));
2217 if (w < minwidth + defwidth && !btn->text.isEmpty())
2218 w = minwidth + defwidth;
2219 if (h < minheight + defwidth)
2220 h = minheight + defwidth;
2227 if (
const QStyleOptionMenuItem *mi = qstyleoption_cast<
const QStyleOptionMenuItem *>(opt)) {
2229 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2231 if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
2232 sz = QSize(10, QWindowsStylePrivate::windowsSepHeight);
2234 else if (mi->icon.isNull()) {
2235 sz.setHeight(sz.height() - 2);
2239 if (mi->menuItemType != QStyleOptionMenuItem::Separator && !mi->icon.isNull()) {
2240 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
2241 sz.setHeight(qMax(sz.height(),
2242 mi->icon.actualSize(QSize(iconExtent, iconExtent)).height()
2243 + 2 * QWindowsStylePrivate::windowsItemFrame));
2245 int maxpmw = mi->maxIconWidth;
2246 int tabSpacing = 20;
2247 if (mi->text.contains(u'\t'))
2249 else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
2250 w += 2 * QWindowsStylePrivate::windowsArrowHMargin;
2251 else if (mi->menuItemType == QStyleOptionMenuItem::DefaultItem) {
2254 QFontMetrics fm(mi->font);
2255 QFont fontBold = mi->font;
2256 fontBold.setBold(
true);
2257 QFontMetrics fmBold(fontBold);
2258 w += fmBold.horizontalAdvance(mi->text) - fm.horizontalAdvance(mi->text);
2261 int checkcol = qMax<
int>(maxpmw, QWindowsStylePrivate::windowsCheckMarkWidth);
2263 w +=
int(QWindowsStylePrivate::windowsRightBorder) + 10;
2268#if QT_CONFIG(menubar)
2269 case CT_MenuBarItem:
2271 sz += QSize(QWindowsStylePrivate::windowsItemHMargin * 4, QWindowsStylePrivate::windowsItemVMargin * 2);
2275#if QT_CONFIG(toolbutton)
2276 if (qstyleoption_cast<
const QStyleOptionToolButton *>(opt))
2277 return sz += QSize(7, 6);
2282 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2288
2289
2290QIcon QWindowsStyle::standardIcon(StandardPixmap standardIcon,
const QStyleOption *option,
2291 const QWidget *widget)
const
2293 return QCommonStyle::standardIcon(standardIcon, option, widget);
2300#include "moc_qwindowsstyle_p.cpp"